diff --git a/app.py b/app.py index 2bdbfbd..22167a3 100644 --- a/app.py +++ b/app.py @@ -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: diff --git a/templates/index.html b/templates/index.html index d4ec4f6..6f33465 100644 --- a/templates/index.html +++ b/templates/index.html @@ -176,6 +176,7 @@
🏷 Tilbud + 🛒 Køb nu 📊 Analyse 🕑 Historik diff --git a/templates/koeb_nu.html b/templates/koeb_nu.html new file mode 100644 index 0000000..e862d45 --- /dev/null +++ b/templates/koeb_nu.html @@ -0,0 +1,160 @@ + + + + + +Citti · Køb nu + + + + +
+ +
+
+

Citti Køb nu

+
Status for din seddel · tilbud fra CITTI Lübeck · mængder uændret
+
+ ← Indkøbsseddel +
+ +{% if not has_offers %} +
Ingen tilbud hentet endnu — åbn Tilbud og tryk Opdater først.
+{% endif %} + +
+
+
Krydset af
+
{{ bought }}/{{ total }}
+
varer købt
+
+
+
Mangler
+
{{ total - bought }}
+
ikke krydset af endnu
+
+
+
På tilbud
+
{{ on_offer|length }}
+
af dine varer lige nu
+
+
+ + +
+
🏷 Dine varer på tilbud nu
+ {% if on_offer %} + {% for r in on_offer %} +
+
+
{{ r.sec.emoji }} {{ r.item.name }}{% if r.bought %} ✓{% endif %}
+
{{ r.offer.heading }} · {{ r.offer.catalog }}{% if r.offer.page %} · s. {{ r.offer.page }}{% endif %}
+
+
+
{{ "{:.2f}".format(r.offer.price_eur).replace(".",",") }} € ≈ {{ "{:.0f}".format(r.offer_dkk) }} kr.
+ {% if r.offer.unit and r.offer.size_from %}
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 }}
{% endif %} +
+
+ {% endfor %} + {% else %} +
Ingen af dine faste varer er på tilbud lige nu.
+ {% endif %} +
+ + +
+
🛒 Mangler at krydse af
+ {% if remaining or picks_remaining %} + {% for g in remaining %} +
+
{{ g.sec.emoji }} {{ g.sec.title }}
+
+ {% for it in g.varer %}{{ it.name }}{% endfor %} +
+
+ {% endfor %} + {% if picks_remaining %} +
+
🏷 Lübeck-tilbud
+
+ {% for p in picks_remaining %}{{ p.heading }}{% endfor %} +
+
+ {% endif %} + {% else %} +
Alt er krydset af — godt gået! 🎉
+ {% endif %} +
+ + +{% if other %} +
+
✨ Ugens tilbud — billige fund (ikke på din liste)
+ {% for o in other %} +
+
+
{{ o.heading }}
+
{{ o.catalog }}{% if o.page %} · s. {{ o.page }}{% endif %}{% if o.unit and o.size_from %} · {{ o.size_from|int }} {{ o.unit }}{% endif %}
+
+
+
{{ "{:.2f}".format(o.price_eur).replace(".",",") }} €
+
≈ {{ "{:.0f}".format(o.dkk) }} kr.
+
+
+ {% endfor %} + +
+{% endif %} + +
+ +