From c08ad5dd0acd9998f9b17496418efb5d9919e03c Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Sun, 28 May 2023 19:11:18 +0200 Subject: [PATCH] isWeighted for billa, hofer, lidl, spar --- stores/billa.js | 1 + stores/hofer.js | 1 + stores/lidl.js | 46 +++++++++++++++++++++++++++------------------- stores/spar.js | 1 + 4 files changed, 30 insertions(+), 19 deletions(-) diff --git a/stores/billa.js b/stores/billa.js index 6a085c6..a7d052e 100644 --- a/stores/billa.js +++ b/stores/billa.js @@ -41,6 +41,7 @@ exports.getCanonical = function(item, today) { name: item.data.name, price: item.data.price.final, priceHistory: [{ date: today, price: item.data.price.final }], + isWeighted : item.data.isWeightArticle, unit, quantity, bio: item.data.attributes && item.data.attributes.includes("s_bio") diff --git a/stores/hofer.js b/stores/hofer.js index 23aaf9f..fc190ec 100644 --- a/stores/hofer.js +++ b/stores/hofer.js @@ -56,6 +56,7 @@ exports.getCanonical = function(item, today) { name: item.ProductName, price: item.Price, priceHistory: [{ date: today, price: item.Price }], + isWeighted: item.IsBulk, unit, quantity, bio: item.IsBio diff --git a/stores/lidl.js b/stores/lidl.js index 6c7b4e4..b624d8d 100644 --- a/stores/lidl.js +++ b/stores/lidl.js @@ -18,28 +18,36 @@ exports.getCanonical = function(item, today) { let quantity = 1; let unit = ''; let text = (item.price.basePrice?.text ?? "").trim().split('(')[0].replaceAll(',', '.').toLowerCase(); - if(text.startsWith('bei') && text.search('je ') != -1) - text = text.substr(text.search('je ')) + let isWeighted = false; - for (let s of ['ab ', 'je ', 'ca. ', 'z.b.: ', 'z.b. ']) - text = text.replace(s, '').trim() + if(text === 'per kg') { + isWeighted = true; + unit = 'kg'; + } + else { + if(text.startsWith('bei') && text.search('je ') != -1) + text = text.substr(text.search('je ')) - const regex = /^([0-9.x ]+)(.*)$/; - const matches = text.match(regex); - if(matches) { - matches[1].split('x').forEach( (q)=> { - quantity = quantity * parseFloat(q.split('/')[0]) - }) - unit = matches[2].split('/')[0].trim().split(' ')[0]; + for (let s of ['ab ', 'je ', 'ca. ', 'z.b.: ', 'z.b. ']) + text = text.replace(s, '').trim() + + const regex = /^([0-9.x ]+)(.*)$/; + const matches = text.match(regex); + if(matches) { + matches[1].split('x').forEach( (q)=> { + quantity = quantity * parseFloat(q.split('/')[0]) + }) + unit = matches[2].split('/')[0].trim().split(' ')[0]; + } + unit = unit.split('-')[0]; + if(unit in conversions) { + const conv = conversions[unit]; + quantity = conv.factor * quantity; + unit = conv.unit; + } + else + console.error(`Unknown unit in lidl: '${unit}'`) } - unit = unit.split('-')[0]; - if(unit in conversions) { - const conv = conversions[unit]; - quantity = conv.factor * quantity; - unit = conv.unit; - } - else - console.error(`Unknown unit in lidl: '${unit}'`) return { id: item.productId, diff --git a/stores/spar.js b/stores/spar.js index 19e6cdd..f434579 100644 --- a/stores/spar.js +++ b/stores/spar.js @@ -50,6 +50,7 @@ exports.getCanonical = function(item, today) { priceHistory: [{ date: today, price }], unit, quantity, + isWeighted: item.masterValues['item-type'] === 'WeightProduct', bio: item.masterValues.biolevel === "Bio" }; }