2023-05-25 13:54:28 +02:00
|
|
|
const axios = require("axios");
|
2023-05-28 19:48:06 +02:00
|
|
|
const utils = require("./utils");
|
2023-05-25 13:54:28 +02:00
|
|
|
const HITS = Math.floor(30000 + Math.random() * 2000);
|
|
|
|
|
2023-05-27 22:00:27 +02:00
|
|
|
const conversions = {
|
|
|
|
"Beutel": { unit: 'stk', factor: 1 },
|
|
|
|
"Blatt": { unit: 'stk', factor: 1 },
|
|
|
|
"Bund": { unit: 'stk', factor: 1 },
|
|
|
|
"g": { unit: 'g', factor: 1},
|
|
|
|
"Gramm": { unit: 'g', factor: 1},
|
|
|
|
"kg": { unit: 'g', factor: 1000},
|
|
|
|
"Kilogramm": { unit: 'g', factor: 1},
|
|
|
|
"l": { unit: 'ml', factor: 1000},
|
|
|
|
"Liter": { unit: 'ml', factor: 1000},
|
|
|
|
"Meter": { unit: 'cm', factor: 100},
|
|
|
|
"Milliliter": { unit: 'ml', factor: 1},
|
|
|
|
"ml": { unit: 'ml', factor: 1},
|
|
|
|
"Paar": { unit: 'stk', factor: 1 },
|
|
|
|
"Packung": { unit: 'stk', factor: 1 },
|
|
|
|
"Portion": { unit: 'stk', factor: 1 },
|
|
|
|
"Rollen": { unit: 'stk', factor: 1 },
|
|
|
|
"Stk": { unit: 'stk', factor: 1 },
|
|
|
|
"Stück": { unit: 'stk', factor: 1 },
|
|
|
|
"Teebeutel": { unit: 'stk', factor: 1 },
|
|
|
|
"Waschgang": { unit: 'wg', factor: 1 },
|
|
|
|
"Zentimeter": { unit: 'cm', factor: 1 },
|
|
|
|
};
|
|
|
|
|
2023-05-25 13:54:28 +02:00
|
|
|
exports.getCanonical = function(item, today) {
|
2023-05-27 22:00:27 +02:00
|
|
|
let quantity = 1, unit = "kg";
|
|
|
|
if(item.data.grammagePriceFactor == 1) {
|
|
|
|
const grammage = item.data.grammage !== "" && item.data.grammage.trim().split(' ').length>1 ? item.data.grammage : item.data.price.unit;
|
2023-05-29 01:08:00 +02:00
|
|
|
if (grammage) [quantity, unit] = grammage.trim().split(' ').splice(0,2);
|
2023-05-27 22:00:27 +02:00
|
|
|
}
|
2023-05-28 19:48:06 +02:00
|
|
|
return utils.convertUnit({
|
2023-05-25 13:54:28 +02:00
|
|
|
id: item.data.articleId,
|
|
|
|
name: item.data.name,
|
|
|
|
price: item.data.price.final,
|
|
|
|
priceHistory: [{ date: today, price: item.data.price.final }],
|
2023-05-28 19:11:18 +02:00
|
|
|
isWeighted : item.data.isWeightArticle,
|
2023-05-27 22:00:27 +02:00
|
|
|
unit,
|
|
|
|
quantity,
|
2023-05-26 18:12:29 +02:00
|
|
|
bio: item.data.attributes && item.data.attributes.includes("s_bio"),
|
2023-05-28 22:31:12 +02:00
|
|
|
url: `https://shop.billa.at${item.data.canonicalPath}`,
|
2023-05-28 19:48:06 +02:00
|
|
|
}, conversions, 'billa');
|
2023-05-25 13:54:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
exports.fetchData = async function() {
|
|
|
|
const BILLA_SEARCH = `https://shop.billa.at/api/search/full?searchTerm=*&storeId=00-10&pageSize=${HITS}`;
|
|
|
|
return (await axios.get(BILLA_SEARCH)).data.tiles;
|
2023-05-27 22:00:27 +02:00
|
|
|
}
|