From 13269580985159f479bf2c540c256afef2ffcd59 Mon Sep 17 00:00:00 2001 From: Dicken Date: Wed, 8 Jul 2026 17:28:08 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20K=C3=B6Pi=20-=20nur=20K=C3=B6nig=20Pilse?= =?UTF-8?q?ner=20anzeigen,=20Flaschengr=C3=B6=C3=9Fe=20erg=C3=A4nzt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/tools/koepi/routes.js | 27 +++++++++++++++++++-------- frontend/src/tools/koepi.jsx | 5 +++-- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/backend/src/tools/koepi/routes.js b/backend/src/tools/koepi/routes.js index f2b2ca5..3bc1b48 100644 --- a/backend/src/tools/koepi/routes.js +++ b/backend/src/tools/koepi/routes.js @@ -123,14 +123,25 @@ async function scrapeOffersWithPuppeteer() { const grid = document.querySelector('[data-testid="OfferGrid"]'); const gridOffers = grid ? Array.from(grid.querySelectorAll('[role="listitem"]')).map(item => { const img = item.querySelector('img'); - const ps = item.querySelectorAll('p'); - const brand = ps[0]?.textContent?.trim() || null; - const name = ps[1]?.textContent?.trim() || null; - const store = ps[2]?.textContent?.trim() || null; - const price = item.querySelector('.text-primary, [class*="text-primary"]')?.textContent?.trim() || null; - const baseUnit = ps[3]?.textContent?.trim() || null; - return { type:'offer', brand, name, store, price, baseUnit, image: img?.src || null }; - }).filter(o => o.name) : []; + const ps = Array.from(item.querySelectorAll('p')).map(p => p.textContent.trim()); + const brand = ps[0] || null; + const name = ps[1] || null; + const store = ps[2] || null; + const price = item.querySelector('[class*="text-primary"]')?.textContent?.trim() || null; + const baseUnit = ps[5] || ps[4] || null; // z.B. "(1 L = 1,20)" + const imgTitle = img?.title || ''; + const imgAlt = img?.alt || ''; + // Flaschengröße aus imgTitle/imgAlt extrahieren + const sizeMatch = (imgTitle + ' ' + imgAlt).match(/(\d+[\.,]\d*\s*[lLxX×]\s*\d*\s*(?:Fl\.?|Flasche|Flaschen|Dose|Dosen|Pack|Kiste)?|\d+\s*(?:×|x)\s*\d+[\.,]\d*\s*[lL]|\d+\s*[lL]|\d+\s*ml)/i); + const size = sizeMatch?.[0]?.trim() || null; + return { type:'offer', brand, name, store, price, baseUnit, size, image: img?.src || null, imgTitle }; + }).filter(o => { + if (!o.name) return false; + // Nur König Pilsener — kein König Ludwig, König der Löwen etc. + const fullText = (o.imgTitle + ' ' + (o.brand||'') + ' ' + (o.name||'')).toLowerCase(); + return fullText.includes('pilsener') || fullText.includes('pilsen') || + (fullText.includes('könig') && !fullText.includes('ludwig') && !fullText.includes('löwen') && !fullText.includes('weiss')); + }) : []; return { brochureOffers, gridOffers }; }); diff --git a/frontend/src/tools/koepi.jsx b/frontend/src/tools/koepi.jsx index e8b52c5..85ee636 100644 --- a/frontend/src/tools/koepi.jsx +++ b/frontend/src/tools/koepi.jsx @@ -128,8 +128,9 @@ function GridOfferCard({ offer }) { {offer.price} )} - {offer.baseUnit && ( -
+ {(offer.size || offer.baseUnit) && ( +
+ {offer.size && {offer.size} · } {offer.baseUnit}
)}