mirror of
https://github.com/badlogic/heissepreise.git
synced 2024-06-28 03:16:12 +02:00
isWeighted for billa, hofer, lidl, spar
This commit is contained in:
parent
2a19207064
commit
c08ad5dd0a
|
@ -41,6 +41,7 @@ exports.getCanonical = function(item, today) {
|
||||||
name: item.data.name,
|
name: item.data.name,
|
||||||
price: item.data.price.final,
|
price: item.data.price.final,
|
||||||
priceHistory: [{ date: today, price: item.data.price.final }],
|
priceHistory: [{ date: today, price: item.data.price.final }],
|
||||||
|
isWeighted : item.data.isWeightArticle,
|
||||||
unit,
|
unit,
|
||||||
quantity,
|
quantity,
|
||||||
bio: item.data.attributes && item.data.attributes.includes("s_bio")
|
bio: item.data.attributes && item.data.attributes.includes("s_bio")
|
||||||
|
|
|
@ -56,6 +56,7 @@ exports.getCanonical = function(item, today) {
|
||||||
name: item.ProductName,
|
name: item.ProductName,
|
||||||
price: item.Price,
|
price: item.Price,
|
||||||
priceHistory: [{ date: today, price: item.Price }],
|
priceHistory: [{ date: today, price: item.Price }],
|
||||||
|
isWeighted: item.IsBulk,
|
||||||
unit,
|
unit,
|
||||||
quantity,
|
quantity,
|
||||||
bio: item.IsBio
|
bio: item.IsBio
|
||||||
|
|
|
@ -18,28 +18,36 @@ exports.getCanonical = function(item, today) {
|
||||||
let quantity = 1;
|
let quantity = 1;
|
||||||
let unit = '';
|
let unit = '';
|
||||||
let text = (item.price.basePrice?.text ?? "").trim().split('(')[0].replaceAll(',', '.').toLowerCase();
|
let text = (item.price.basePrice?.text ?? "").trim().split('(')[0].replaceAll(',', '.').toLowerCase();
|
||||||
if(text.startsWith('bei') && text.search('je ') != -1)
|
let isWeighted = false;
|
||||||
text = text.substr(text.search('je '))
|
|
||||||
|
|
||||||
for (let s of ['ab ', 'je ', 'ca. ', 'z.b.: ', 'z.b. '])
|
if(text === 'per kg') {
|
||||||
text = text.replace(s, '').trim()
|
isWeighted = true;
|
||||||
|
unit = 'kg';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(text.startsWith('bei') && text.search('je ') != -1)
|
||||||
|
text = text.substr(text.search('je '))
|
||||||
|
|
||||||
const regex = /^([0-9.x ]+)(.*)$/;
|
for (let s of ['ab ', 'je ', 'ca. ', 'z.b.: ', 'z.b. '])
|
||||||
const matches = text.match(regex);
|
text = text.replace(s, '').trim()
|
||||||
if(matches) {
|
|
||||||
matches[1].split('x').forEach( (q)=> {
|
const regex = /^([0-9.x ]+)(.*)$/;
|
||||||
quantity = quantity * parseFloat(q.split('/')[0])
|
const matches = text.match(regex);
|
||||||
})
|
if(matches) {
|
||||||
unit = matches[2].split('/')[0].trim().split(' ')[0];
|
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 {
|
return {
|
||||||
id: item.productId,
|
id: item.productId,
|
||||||
|
|
|
@ -50,6 +50,7 @@ exports.getCanonical = function(item, today) {
|
||||||
priceHistory: [{ date: today, price }],
|
priceHistory: [{ date: today, price }],
|
||||||
unit,
|
unit,
|
||||||
quantity,
|
quantity,
|
||||||
|
isWeighted: item.masterValues['item-type'] === 'WeightProduct',
|
||||||
bio: item.masterValues.biolevel === "Bio"
|
bio: item.masterValues.biolevel === "Bio"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user