feat(koeb-nu): read-only "buy now" shopping status vs current offers

Add a /koeb-nu page that analyses the list without touching quantities:
- which fixed items are on offer in Lübeck right now (honest per-unit
  offer price in EUR + DKK, no fabricated saving vs the Danish-origin
  estimate, since the units differ)
- what still needs ticking off, grouped by section (+ picked offers)
- a selection of this week's cheapest Tilbud specials not on the list,
  linking to the full Tilbud page
Header gets a 🛒 Køb nu link. The source carries no pre-price, so no
discount % is shown.
This commit is contained in:
Henrik Jess Nielsen
2026-10-30 10:43:22 +01:00
parent 65a99d2138
commit 3b0ea28db5
3 changed files with 220 additions and 0 deletions

59
app.py
View File

@@ -616,6 +616,65 @@ def offer_refresh():
return jsonify(ok=True, **summary)
@app.route('/koeb-nu')
def koeb_nu():
with get_db() as c:
saved = {r['key']: dict(r) for r in c.execute("SELECT * FROM prices")}
offers = [dict(r) for r in c.execute("SELECT * FROM offers")]
picks = [dict(r) for r in c.execute(
"SELECT * FROM offers WHERE picked=1 ORDER BY catalog, heading")]
deals = match_catalog_offers(offers) if offers else {}
# 1) Your fixed items currently on offer. No "saving vs estimate" — the
# estimate is the whole line (e.g. 6 × ½ kg) while the offer price is per
# unit (e.g. per 100 g), so a kr-diff would be misleading. Show the honest
# offer price + unit instead.
on_offer = []
for sec in SECTIONS:
for item in sec['varer']:
d = deals.get(item['key'])
if not d:
continue
on_offer.append({
'item': item, 'sec': sec, 'offer': d,
'offer_dkk': (d.get('price_eur') or 0) * EUR_DKK,
'bought': bool(saved.get(item['key'], {}).get('checked')),
})
on_offer.sort(key=lambda r: (r['bought'], -(r['offer'].get('price_eur') or 0)))
# 2) What still needs to be ticked off (fixed items + picked offers)
remaining = []
for sec in SECTIONS:
items = [it for it in sec['varer']
if not saved.get(it['key'], {}).get('checked')]
if items:
remaining.append({'sec': sec, 'varer': items})
picks_remaining = [p for p in picks if not saved.get(p['id'], {}).get('checked')]
# 3) A taste of this week's headline "Tilbud" specials not already on the
# list (the source carries no pre-price, so there is no discount % to rank
# by; show the cheapest finds and link to the full Tilbud page).
on_list_ids = set(deals[k]['id'] for k in deals) | set(p['id'] for p in picks)
other = []
for o in offers:
if o.get('catalog') == 'Tilbud' and o['id'] not in on_list_ids and o.get('price_eur'):
o = dict(o)
o['dkk'] = o['price_eur'] * EUR_DKK
other.append(o)
other.sort(key=lambda o: o['price_eur'])
other = other[:25]
total = sum(len(sec['varer']) for sec in SECTIONS) + len(picks)
bought = sum(1 for sec in SECTIONS for it in sec['varer']
if saved.get(it['key'], {}).get('checked')) \
+ sum(1 for p in picks if saved.get(p['id'], {}).get('checked'))
return render_template('koeb_nu.html', on_offer=on_offer, remaining=remaining,
picks_remaining=picks_remaining, other=other,
eur_dkk=EUR_DKK, total=total, bought=bought,
has_offers=bool(offers))
@app.route('/analyse')
def analyse():
with get_db() as c:

View File

@@ -176,6 +176,7 @@
<div style="display:flex;gap:8px;flex-wrap:wrap">
<button class="btn btn-cat" onclick="openCatModal()">+ Kategori</button>
<a href="/tilbud" class="btn">🏷 Tilbud</a>
<a href="/koeb-nu" class="btn">🛒 Køb nu</a>
<a href="/analyse" class="btn">📊 Analyse</a>
<a href="/historik" class="btn">🕑 Historik</a>
<button class="btn" onclick="openArchiveModal()">🗂 Arkivér & ny liste</button>

160
templates/koeb_nu.html Normal file
View File

@@ -0,0 +1,160 @@
<!DOCTYPE html>
<html lang="da">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Citti · Køb nu</title>
<link href="https://fonts.googleapis.com/css2?family=DM+Mono:wght@400;500&family=DM+Sans:wght@300;400;500;600&display=swap" rel="stylesheet">
<style>
:root {
--bg: #f5f2ed; --card: #ffffff; --border: #e2ddd6; --text: #1a1814;
--muted: #8a857c; --accent: #c84b2f; --green: #2d6a4f; --green-light: #e8f4ee;
--mono: 'DM Mono', monospace; --sans: 'DM Sans', sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--sans); background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; padding: 1.5rem 1rem 4rem; }
.page { max-width: 860px; margin: 0 auto; }
header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; padding-bottom: 1.25rem; border-bottom: 2px solid var(--text); }
h1 { font-size: 1.75rem; font-weight: 600; letter-spacing: -0.03em; }
h1 span { color: var(--accent); }
.sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.btn-back { background: var(--text); color: white; border: none; border-radius: 8px; padding: 8px 14px; font-size: 13px; font-family: var(--sans); cursor: pointer; text-decoration: none; display: inline-block; font-weight: 500; }
.kpi-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 1.5rem; }
.kpi { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 1rem; }
.kpi-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 4px; }
.kpi-val { font-size: 1.75rem; font-weight: 600; font-family: var(--mono); letter-spacing: -0.02em; }
.kpi-val.green { color: var(--green); }
.kpi-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; margin-bottom: 1.25rem; }
.card-title { background: var(--text); color: white; padding: 0.6rem 1rem; font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; }
.card-title.green { background: var(--green); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.6rem 1rem; border-bottom: 1px solid var(--border); }
.row:last-child { border-bottom: none; }
.row.bought { opacity: 0.45; }
.row.bought .r-name { text-decoration: line-through; }
.r-name { font-size: 14px; font-weight: 500; }
.r-meta { font-size: 11px; color: var(--muted); margin-top: 1px; }
.r-right { text-align: right; white-space: nowrap; }
.r-price { font-family: var(--mono); font-weight: 600; }
.r-pre { font-family: var(--mono); font-size: 12px; color: var(--muted); text-decoration: line-through; margin-right: 4px; }
.r-save { font-size: 11px; color: var(--green); font-weight: 600; }
.r-dkk { font-size: 11px; color: var(--muted); font-family: var(--mono); }
.pill { display: inline-block; font-size: 10px; font-weight: 600; background: var(--accent); color: #fff; border-radius: 4px; padding: 1px 6px; margin-left: 6px; }
.sec-group { padding: 0.5rem 1rem; border-bottom: 1px solid var(--border); }
.sec-group:last-child { border-bottom: none; }
.sec-h { font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 3px 9px; }
.empty-state { padding: 2rem; text-align: center; color: var(--muted); font-size: 14px; }
@media (max-width: 600px) { .kpi-val { font-size: 1.35rem; } }
</style>
</head>
<body>
<div class="page">
<header>
<div>
<h1>Citti <span>Køb nu</span></h1>
<div class="sub">Status for din seddel · tilbud fra CITTI Lübeck · mængder uændret</div>
</div>
<a href="/" class="btn-back">← Indkøbsseddel</a>
</header>
{% if not has_offers %}
<div class="card"><div class="empty-state">Ingen tilbud hentet endnu — åbn <a href="/tilbud">Tilbud</a> og tryk Opdater først.</div></div>
{% endif %}
<div class="kpi-row">
<div class="kpi">
<div class="kpi-label">Krydset af</div>
<div class="kpi-val">{{ bought }}<span style="font-size:1rem;color:var(--muted)">/{{ total }}</span></div>
<div class="kpi-sub">varer købt</div>
</div>
<div class="kpi">
<div class="kpi-label">Mangler</div>
<div class="kpi-val">{{ total - bought }}</div>
<div class="kpi-sub">ikke krydset af endnu</div>
</div>
<div class="kpi">
<div class="kpi-label">På tilbud</div>
<div class="kpi-val green">{{ on_offer|length }}</div>
<div class="kpi-sub">af dine varer lige nu</div>
</div>
</div>
<!-- 1) DINE VARER PÅ TILBUD -->
<div class="card">
<div class="card-title green">🏷 Dine varer på tilbud nu</div>
{% if on_offer %}
{% for r in on_offer %}
<div class="row{% if r.bought %} bought{% endif %}">
<div>
<div class="r-name">{{ r.sec.emoji }} {{ r.item.name }}{% if r.bought %} ✓{% endif %}</div>
<div class="r-meta">{{ r.offer.heading }} · {{ r.offer.catalog }}{% if r.offer.page %} · s. {{ r.offer.page }}{% endif %}</div>
</div>
<div class="r-right">
<div class="r-price">{{ "{:.2f}".format(r.offer.price_eur).replace(".",",") }} € <span class="r-dkk">≈ {{ "{:.0f}".format(r.offer_dkk) }} kr.</span></div>
{% if r.offer.unit and r.offer.size_from %}<div class="r-dkk">pr. {{ r.offer.size_from|int }}{% if r.offer.size_to and r.offer.size_to != r.offer.size_from %}–{{ r.offer.size_to|int }}{% endif %} {{ r.offer.unit }}</div>{% endif %}
</div>
</div>
{% endfor %}
{% else %}
<div class="empty-state">Ingen af dine faste varer er på tilbud lige nu.</div>
{% endif %}
</div>
<!-- 2) MANGLER AT KØBE -->
<div class="card">
<div class="card-title">🛒 Mangler at krydse af</div>
{% if remaining or picks_remaining %}
{% for g in remaining %}
<div class="sec-group">
<div class="sec-h">{{ g.sec.emoji }} {{ g.sec.title }}</div>
<div class="chips">
{% for it in g.varer %}<span class="chip">{{ it.name }}</span>{% endfor %}
</div>
</div>
{% endfor %}
{% if picks_remaining %}
<div class="sec-group">
<div class="sec-h">🏷 Lübeck-tilbud</div>
<div class="chips">
{% for p in picks_remaining %}<span class="chip">{{ p.heading }}</span>{% endfor %}
</div>
</div>
{% endif %}
{% else %}
<div class="empty-state">Alt er krydset af — godt gået! 🎉</div>
{% endif %}
</div>
<!-- 3) UGENS TILBUD — UDVALG -->
{% if other %}
<div class="card">
<div class="card-title">✨ Ugens tilbud — billige fund (ikke på din liste)</div>
{% for o in other %}
<div class="row">
<div>
<div class="r-name">{{ o.heading }}</div>
<div class="r-meta">{{ o.catalog }}{% if o.page %} · s. {{ o.page }}{% endif %}{% if o.unit and o.size_from %} · {{ o.size_from|int }} {{ o.unit }}{% endif %}</div>
</div>
<div class="r-right">
<div class="r-price">{{ "{:.2f}".format(o.price_eur).replace(".",",") }} €</div>
<div class="r-dkk">≈ {{ "{:.0f}".format(o.dkk) }} kr.</div>
</div>
</div>
{% endfor %}
<div class="row" style="justify-content:center">
<a href="/tilbud" style="color:var(--accent);font-size:13px;font-weight:600;text-decoration:none">Se alle tilbud →</a>
</div>
</div>
{% endif %}
</div>
</body>
</html>