feat(offers): live Lübeck offer prices with pick-to-list and deal matching

Fetch CITTI Lübeck offers from the Tjek API (German dealer 3czmZx only —
never the Danish Flensburg booklet) and surface them in the app.

- New offers + offer_meta tables; defensive hotspots parser; upsert by
  offer id, prune per re-fetched catalog while preserving picked rows
- Daily in-process refresh scheduler (data.db lives on the app's own
  Nomad alloc disk, so a separate periodic job can't share it) plus a
  manual POST /api/offers/refresh and an "Opdater" button
- /tilbud page: browse all offers by catalog, search, EUR + DKK, and tick
  offers onto the shopping list; picks appear in a Lübeck-tilbud section
  on the main list and check off as bought via the existing /api/price
- Match the fixed catalog items against current offers and show a
  "på tilbud" badge with the matched offer name (conservative word-
  boundary token match, >=2 tokens for multi-word names)
- Dockerfile: add ca-certificates for urllib HTTPS to the Tjek API
This commit is contained in:
Henrik Jess Nielsen
2026-10-30 10:35:43 +01:00
parent cf999ae228
commit 65a99d2138
4 changed files with 498 additions and 2 deletions

View File

@@ -60,6 +60,7 @@
.badge { display: inline-block; font-size: 9px; padding: 1px 5px; border-radius: 3px; margin-left: 5px; vertical-align: middle; font-weight: 500; }
.badge-card { background: var(--blue-light); color: var(--blue); }
.badge-kasse { background: var(--amber-light); color: var(--amber); }
.item-name .deal { font-size: 11px; color: var(--green); background: var(--green-light); display: inline-block; margin-top: 3px; padding: 2px 7px; border-radius: 5px; font-weight: 600; text-decoration: none; line-height: 1.3; }
.item-qty { padding: 0.35rem 0.4rem; }
.item-qty input { width: 100%; border: 1px solid var(--border); border-radius: 5px; padding: 6px 5px; font-size: 11px; font-family: var(--mono); background: var(--bg); color: var(--muted); text-align: center; outline: none; transition: border-color 0.15s, background 0.15s; cursor: text; min-height: 32px; }
.item-qty input:focus { border-color: var(--accent); background: white; color: var(--text); }
@@ -174,6 +175,7 @@
<div class="header-actions">
<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="/analyse" class="btn">📊 Analyse</a>
<a href="/historik" class="btn">🕑 Historik</a>
<button class="btn" onclick="openArchiveModal()">🗂 Arkivér & ny liste</button>
@@ -234,6 +236,8 @@
{% if item.get('badges') %}{% for b in item.badges %}{% if b == 'card' %}<span class="badge badge-card">CITTI CARD</span>{% endif %}{% if b == 'kasse' %}<span class="badge badge-kasse">Hel kasse</span>{% endif %}{% endfor %}{% endif %}
{% if item.get('de') %}<span class="de">🇩🇪 {{ item.de }}</span>{% endif %}
{% if item.get('note') %}<span class="note">{{ item.note }}</span>{% endif %}
{% set d = deals.get(item.key) %}
{% if d %}<a class="deal" href="/tilbud" title="{{ d.heading }} ({{ d.catalog }})">🏷 på tilbud: {{ "{:.2f}".format(d.price_eur).replace(".",",") }} € ≈ {{ "{:.0f}".format(d.price_eur * eur_dkk) }} kr. · {{ d.heading }}</a>{% endif %}
</div>
<div class="item-qty">
<input type="text" value="{{ s.get('qty') or item.qty }}" placeholder="{{ item.qty }}"
@@ -261,6 +265,34 @@
</div>
{% endfor %}
<!-- LÜBECK-TILBUD (valgt på Tilbud-siden) -->
<div class="section" id="sec-picks"{% if not picks %} style="display:none"{% endif %}>
<div class="section-header" style="background:#2d6a4f">
<span class="emoji">🏷</span> Lübeck-tilbud
<span class="est"><a href="/tilbud" style="color:#fff;text-decoration:underline">vælg flere →</a></span>
</div>
<div class="items-table" id="picks-table">
{% for o in picks %}
{% set ps = saved.get(o.id, {}) %}
<div class="item-row{% if ps.get('checked') %} checked{% endif %}" data-key="{{ o.id }}" id="pick-{{ o.id }}">
<div class="item-check"><input type="checkbox" {% if ps.get('checked') %}checked{% endif %} onchange="toggleOffer(this)"></div>
<div class="item-name">
{{ o.heading }}
<span class="note">{{ o.catalog }}{% if o.page %} · s. {{ o.page }}{% endif %}{% if o.unit %} · {{ o.size_from|int if o.size_from else '' }}{{ o.unit }}{% endif %}</span>
</div>
<div class="item-qty" style="display:flex;align-items:center;color:var(--muted);font-size:12px">
{% if o.pre_price_eur %}<s>{{ "{:.2f}".format(o.pre_price_eur).replace(".",",") }}</s>{% endif %}
</div>
<div class="item-est">{{ "{:.2f}".format(o.price_eur).replace(".",",") }} €</div>
<div class="item-actual" style="display:flex;align-items:center;gap:6px;justify-content:flex-end">
<span style="font-family:var(--mono)">≈ {{ "{:.0f}".format(o.price_eur * eur_dkk) }} kr.</span>
<button class="eir-del" onclick="removeOffer('{{ o.id }}')" title="Fjern fra seddel" style="border:none;background:none;cursor:pointer">×</button>
</div>
</div>
{% endfor %}
</div>
</div>
<!-- DYNAMISKE SEKTIONER -->
<div id="custom-sections">
{% for cs in custom_secs %}
@@ -639,6 +671,26 @@ async function deleteCategory(id) {
document.getElementById(`csec-${id}`).remove();
}
function toggleOffer(cb) {
const row = cb.closest('.item-row');
row.classList.toggle('checked', cb.checked);
saveToServer(row.dataset.key, null, cb.checked ? 1 : 0);
}
async function removeOffer(id) {
await fetch('/api/offers/pick', {
method: 'POST',
headers: {'Content-Type':'application/json'},
body: JSON.stringify({id, picked: false})
});
const row = document.getElementById('pick-' + id);
if (row) row.remove();
if (!document.querySelectorAll('#picks-table .item-row').length) {
document.getElementById('sec-picks').style.display = 'none';
}
showSaved();
}
function openArchiveModal() {
document.getElementById('archive-modal').classList.add('open');
}