From a64edaf22ffb37895234b52ad05e58057a9cb238 Mon Sep 17 00:00:00 2001 From: Norbert Maciaszek Date: Sat, 15 Nov 2025 20:36:05 +0100 Subject: [PATCH] Initialize productsPrice.json if it doesn't exist and update log message to Polish --- index.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index c51b785..a5ea242 100644 --- a/index.js +++ b/index.js @@ -25,8 +25,11 @@ function sendMessage(message) { } async function compareAndSave(productsPrice) { - const productsPriceJson = - fs.readFileSync("productsPrice.json", "utf8") || "[]"; + if (!fs.existsSync("productsPrice.json")) { + fs.writeFileSync("productsPrice.json", "[]"); + } + + const productsPriceJson = fs.readFileSync("productsPrice.json", "utf8"); const oldProductsPrice = JSON.parse(productsPriceJson); const diffProducts = []; @@ -139,7 +142,7 @@ async function init() { await compareAndSave(productsPrice); - console.log("Done! Check productsPrice.json"); + console.log("Sprawdzone! Aktualne ceny zapisane w productsPrice.json"); } sendMessage("Zaczynam monitoring cen");