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-06-03 15:09:29 +02:00
|
|
|
const units = {
|
|
|
|
beutel: { unit: "stk", factor: 1 },
|
|
|
|
bund: { unit: "stk", factor: 1 },
|
|
|
|
packung: { unit: "stk", factor: 1 },
|
|
|
|
portion: { unit: "stk", factor: 1 },
|
|
|
|
rollen: { unit: "stk", factor: 1 },
|
|
|
|
teebeutel: { unit: "stk", factor: 1 },
|
|
|
|
waschgang: { unit: "wg", factor: 1 },
|
2023-05-27 22:00:27 +02:00
|
|
|
};
|
|
|
|
|
2023-06-02 16:45:54 +02:00
|
|
|
exports.getCanonical = function (item, today) {
|
|
|
|
let quantity = 1,
|
|
|
|
unit = "kg";
|
2023-06-02 18:34:14 +02:00
|
|
|
|
2023-06-02 16:45:54 +02:00
|
|
|
if (item.data.grammagePriceFactor == 1) {
|
2023-06-03 15:09:29 +02:00
|
|
|
if (item.data.grammage.indexOf("Per ") == 0) item.data.grammage = item.data.grammage.replace("Per ", "");
|
2023-06-02 16:45:54 +02:00
|
|
|
const grammage = item.data.grammage !== "" && item.data.grammage.trim().split(" ").length > 1 ? item.data.grammage : item.data.price.unit;
|
|
|
|
if (grammage) [quantity, unit] = grammage.trim().split(" ").splice(0, 2);
|
2023-05-27 22:00:27 +02:00
|
|
|
}
|
2023-06-02 16:56:22 +02:00
|
|
|
|
2023-06-03 15:09:29 +02:00
|
|
|
return utils.convertUnit(
|
|
|
|
{
|
|
|
|
id: item.data.articleId,
|
|
|
|
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"),
|
|
|
|
url: item.data.canonicalPath,
|
|
|
|
},
|
|
|
|
units,
|
|
|
|
"billa"
|
|
|
|
);
|
|
|
|
};
|
2023-05-25 13:54:28 +02:00
|
|
|
|
2023-06-02 16:45:54 +02:00
|
|
|
exports.fetchData = async function () {
|
2023-05-25 13:54:28 +02:00
|
|
|
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-06-03 15:09:29 +02:00
|
|
|
};
|
2023-06-02 10:38:14 +02:00
|
|
|
|
2023-06-03 15:09:29 +02:00
|
|
|
exports.urlBase = "https://shop.billa.at";
|