diff --git a/categorize.js b/categorize.js index 16e3c9c..34a9aac 100644 --- a/categorize.js +++ b/categorize.js @@ -2,7 +2,7 @@ const fs = require("fs"); const axios = require("axios"); const analysis = require("./analysis"); const stores = require("./stores"); -const utils = require("./stores/utils"); +const { categories } = require("./site/model/categories"); const siteUtils = require("./site/utils"); const HITS = Math.floor(30000 + Math.random() * 2000); @@ -13,8 +13,8 @@ const HITS = Math.floor(30000 + Math.random() * 2000); if (!fs.existsSync("categories.json")) { const lookup = {}; categories = []; - for (let i = 1; i <= utils.globalCategories.length; i++) { - const categoryName = utils.globalCategories[i - 1]; + for (let i = 1; i <= categories.length; i++) { + const categoryName = categories[i - 1]; const categoryCode = i < 10 ? "" + i : String.fromCharCode("A".charCodeAt(0) + (i - 10)); const category = { diff --git a/stores/billa.js b/stores/billa.js index 2ac44b6..c672377 100644 --- a/stores/billa.js +++ b/stores/billa.js @@ -1,6 +1,6 @@ const axios = require("axios"); const utils = require("./utils"); -const { toCategoryCode, fromCategoryCode, getCategory } = require("../site/model/categories"); +const { categories, toCategoryCode, fromCategoryCode, getCategory } = require("../site/model/categories"); const HITS = Math.floor(30000 + Math.random() * 2000); const units = { @@ -45,8 +45,8 @@ exports.fetchData = async function () { const lookup = {}; let numDuplicates = 0; - for (let i = 1; i <= utils.globalCategories.length; i++) { - const category = utils.globalCategories[i - 1]; + for (let i = 1; i <= categories.length; i++) { + const category = categories[i - 1]; const categoryCode = i < 10 ? "" + i : String.fromCharCode("A".charCodeAt(0) + (i - 10)); for (let j = 1; j <= category.subcategories.length; j++) { diff --git a/stores/hofer-categories.json b/stores/hofer-categories.json new file mode 100644 index 0000000..c7dfb84 --- /dev/null +++ b/stores/hofer-categories.json @@ -0,0 +1,711 @@ +[ + { + "id": "obst-gemuse", + "description": "Obst & Gemüse", + "url": "https://www.roksh.at//hofer/angebot/obst-gemuse", + "code": null + }, + { + "id": "gemuse", + "description": "Gemüse", + "url": "https://www.roksh.at//hofer/angebot/obst-gemuse/gemuse", + "code": null + }, + { + "id": "obst", + "description": "Obst", + "url": "https://www.roksh.at//hofer/angebot/obst-gemuse/obst", + "code": null + }, + { + "id": "brot-geback", + "description": "Brot & Gebäck", + "url": "https://www.roksh.at//hofer/angebot/brot-geback", + "code": null + }, + { + "id": "backbox", + "description": "BACKBOX", + "url": "https://www.roksh.at//hofer/angebot/brot-geback/backbox", + "code": null + }, + { + "id": "brot-geback-2", + "description": "Brot & Gebäck", + "url": "https://www.roksh.at//hofer/angebot/brot-geback/brot-geback-2", + "code": null + }, + { + "id": "suße-backwaren", + "description": "Süße Backwaren", + "url": "https://www.roksh.at//hofer/angebot/brot-geback/suße-backwaren", + "code": null + }, + { + "id": "kuhlwaren", + "description": "Kühlwaren", + "url": "https://www.roksh.at//hofer/angebot/kuhlwaren", + "code": null + }, + { + "id": "milch-joghurt-co", + "description": "Milch, Joghurt & Co", + "url": "https://www.roksh.at//hofer/angebot/kuhlwaren/milch-joghurt-co", + "code": null + }, + { + "id": "kase-aufstriche", + "description": "Käse & Aufstriche", + "url": "https://www.roksh.at//hofer/angebot/kuhlwaren/kase-aufstriche", + "code": null + }, + { + "id": "schnell-kuche", + "description": "Schnelle Küche", + "url": "https://www.roksh.at//hofer/angebot/kuhlwaren/schnell-kuche", + "code": null + }, + { + "id": "desserts-und-sußspeise", + "description": "Desserts und Süßspeisen", + "url": "https://www.roksh.at//hofer/angebot/kuhlwaren/desserts-und-sußspeise", + "code": null + }, + { + "id": "eier", + "description": "Eier", + "url": "https://www.roksh.at//hofer/angebot/kuhlwaren/eier", + "code": null + }, + { + "id": "teig-backwaren", + "description": "Teig- & Backwaren", + "url": "https://www.roksh.at//hofer/angebot/kuhlwaren/teig-backwaren", + "code": null + }, + { + "id": "fleisch-fisch-und-wurst", + "description": "Fleisch, Wurst & Fisch", + "url": "https://www.roksh.at//hofer/angebot/fleisch-fisch-und-wurst", + "code": null + }, + { + "id": "wurst-aufschnitt", + "description": "Wurst & Aufschnitt", + "url": "https://www.roksh.at//hofer/angebot/fleisch-fisch-und-wurst/wurst-aufschnitt", + "code": null + }, + { + "id": "fleisch", + "description": "Fleisch", + "url": "https://www.roksh.at//hofer/angebot/fleisch-fisch-und-wurst/fleisch", + "code": null + }, + { + "id": "fisch-meeresfruchte", + "description": "Fisch & Meeresfrüchte", + "url": "https://www.roksh.at//hofer/angebot/fleisch-fisch-und-wurst/fisch-meeresfruchte", + "code": null + }, + { + "id": "vorratsschrank", + "description": "Vorratsschrank", + "url": "https://www.roksh.at//hofer/angebot/vorratsschrank", + "code": null + }, + { + "id": "mehl-backwaren", + "description": "Mehl & Backwaren", + "url": "https://www.roksh.at//hofer/angebot/vorratsschrank/mehl-backwaren", + "code": null + }, + { + "id": "suße-aufstriche", + "description": "Süße Aufstriche", + "url": "https://www.roksh.at//hofer/angebot/vorratsschrank/suße-aufstriche", + "code": null + }, + { + "id": "musli-cerealien", + "description": "Müsli & Cerealien", + "url": "https://www.roksh.at//hofer/angebot/vorratsschrank/musli-cerealien", + "code": null + }, + { + "id": "konserven", + "description": "Konserven", + "url": "https://www.roksh.at//hofer/angebot/vorratsschrank/konserven", + "code": null + }, + { + "id": "fertiggerichte-suppen", + "description": "Fertiggerichte & Suppen", + "url": "https://www.roksh.at//hofer/angebot/vorratsschrank/fertiggerichte-suppen", + "code": null + }, + { + "id": "essig-ol-saucen", + "description": "Essig, Öl & Saucen", + "url": "https://www.roksh.at//hofer/angebot/vorratsschrank/essig-ol-saucen", + "code": null + }, + { + "id": "reis-teigwaren-getreide", + "description": "Reis, Teigwaren & Getreide", + "url": "https://www.roksh.at//hofer/angebot/vorratsschrank/reis-teigwaren-getreide", + "code": null + }, + { + "id": "gewurze", + "description": "Gewürze", + "url": "https://www.roksh.at//hofer/angebot/vorratsschrank/gewurze", + "code": null + }, + { + "id": "nusse-trockenfruchte", + "description": "Nüsse & Trockenfrüchte", + "url": "https://www.roksh.at//hofer/angebot/vorratsschrank/nusse-trockenfruchte", + "code": null + }, + { + "id": "zucker-sußungsmittel", + "description": "Zucker & Süßungsmittel", + "url": "https://www.roksh.at//hofer/angebot/vorratsschrank/zucker-sußungsmittel", + "code": null + }, + { + "id": "sußes-salziges", + "description": "Süßes & Salziges", + "url": "https://www.roksh.at//hofer/angebot/sußes-salziges", + "code": null + }, + { + "id": "sußes", + "description": "Süßes", + "url": "https://www.roksh.at//hofer/angebot/sußes-salziges/sußes", + "code": null + }, + { + "id": "salziges", + "description": "Salziges", + "url": "https://www.roksh.at//hofer/angebot/sußes-salziges/salziges", + "code": null + }, + { + "id": "tiefkuhlwaren", + "description": "Tiefkühlwaren", + "url": "https://www.roksh.at//hofer/angebot/tiefkuhlwaren", + "code": null + }, + { + "id": "fleisch-2", + "description": "Fleisch", + "url": "https://www.roksh.at//hofer/angebot/tiefkuhlwaren/fleisch-2", + "code": null + }, + { + "id": "gemuse-obst", + "description": "Gemüse & Obst", + "url": "https://www.roksh.at//hofer/angebot/tiefkuhlwaren/gemuse-obst", + "code": null + }, + { + "id": "desserts-backwaren-eis", + "description": "Desserts, Backwaren & Eis", + "url": "https://www.roksh.at//hofer/angebot/tiefkuhlwaren/desserts-backwaren-eis", + "code": null + }, + { + "id": "pizza-fertiggerichte", + "description": "Pizza & Fertiggerichte", + "url": "https://www.roksh.at//hofer/angebot/tiefkuhlwaren/pizza-fertiggerichte", + "code": null + }, + { + "id": "fisch-meeresfruchte-2", + "description": "Fisch & Meeresfrüchte", + "url": "https://www.roksh.at//hofer/angebot/tiefkuhlwaren/fisch-meeresfruchte-2", + "code": null + }, + { + "id": "vegetarisch-vegan", + "description": "Vegetarisch & Vegan ", + "url": "https://www.roksh.at//hofer/angebot/vegetarisch-vegan", + "code": null + }, + { + "id": "pflanzliche", + "description": "Pflanzliche Produkte", + "url": "https://www.roksh.at//hofer/angebot/vegetarisch-vegan/pflanzliche", + "code": null + }, + { + "id": "margarine-pflanzliche", + "description": "Margarine & pflanzliche Fette", + "url": "https://www.roksh.at//hofer/angebot/vegetarisch-vegan/margarine-pflanzliche", + "code": null + }, + { + "id": "fleischersatzprodukte", + "description": "Fleischersatz- Produkte", + "url": "https://www.roksh.at//hofer/angebot/vegetarisch-vegan/fleischersatzprodukte", + "code": null + }, + { + "id": "getranke", + "description": "Getränke", + "url": "https://www.roksh.at//hofer/angebot/getranke", + "code": null + }, + { + "id": "spirituosen", + "description": "Spirituosen", + "url": "https://www.roksh.at//hofer/angebot/getranke/spirituosen", + "code": null + }, + { + "id": "wein-sekt", + "description": "Wein & Sekt", + "url": "https://www.roksh.at//hofer/angebot/getranke/wein-sekt", + "code": null + }, + { + "id": "bier-radler", + "description": "Bier & Radler", + "url": "https://www.roksh.at//hofer/angebot/getranke/bier-radler", + "code": null + }, + { + "id": "kaffe-tee-co", + "description": "Kaffee, Tee & Co", + "url": "https://www.roksh.at//hofer/angebot/getranke/kaffe-tee-co", + "code": null + }, + { + "id": "alkoholfreie-getranke", + "description": "Alkoholfreie Getränke", + "url": "https://www.roksh.at//hofer/angebot/getranke/alkoholfreie-getranke", + "code": null + }, + { + "id": "drogerie", + "description": "Drogerie", + "url": "https://www.roksh.at//hofer/angebot/drogerie", + "code": null + }, + { + "id": "hygieneartikel-2", + "description": "Pflege- & Hygieneartikel", + "url": "https://www.roksh.at//hofer/angebot/drogerie/hygieneartikel-2", + "code": null + }, + { + "id": "babyartikel", + "description": "Babyartikel", + "url": "https://www.roksh.at//hofer/angebot/drogerie/babyartikel", + "code": null + }, + { + "id": "gesundheit-medizinprodukte", + "description": "Hausapotheke & Sportnahrung", + "url": "https://www.roksh.at//hofer/angebot/drogerie/gesundheit-medizinprodukte", + "code": null + }, + { + "id": "damensocken-feinstrumpfe", + "description": "Damensocken & Feinstrümpfe", + "url": "https://www.roksh.at//hofer/angebot/drogerie/damensocken-feinstrumpfe", + "code": null + }, + { + "id": "haushalt", + "description": "Haushalt", + "url": "https://www.roksh.at//hofer/angebot/haushalt", + "code": null + }, + { + "id": "waschen-reinigen", + "description": "Waschen & Reinigen", + "url": "https://www.roksh.at//hofer/angebot/haushalt/waschen-reinigen", + "code": null + }, + { + "id": "hygieneartikel", + "description": "Hygieneartikel", + "url": "https://www.roksh.at//hofer/angebot/haushalt/hygieneartikel", + "code": null + }, + { + "id": "servitten", + "description": " Servietten, Kerzen & Co", + "url": "https://www.roksh.at//hofer/angebot/haushalt/servitten", + "code": null + }, + { + "id": "haushaltfolien", + "description": "Haushaltsfolien", + "url": "https://www.roksh.at//hofer/angebot/haushalt/haushaltfolien", + "code": null + }, + { + "id": "tragetaschen", + "description": "Tragetaschen", + "url": "https://www.roksh.at//hofer/angebot/haushalt/tragetaschen", + "code": null + }, + { + "id": "batterien-akkus", + "description": "Batterien & Akkus", + "url": "https://www.roksh.at//hofer/angebot/haushalt/batterien-akkus", + "code": null + }, + { + "id": "tierberdarf", + "description": "Tierbedarf", + "url": "https://www.roksh.at//hofer/angebot/tierberdarf", + "code": null + }, + { + "id": "hundenahrung", + "description": "Hundenahrung", + "url": "https://www.roksh.at//hofer/angebot/tierberdarf/hundenahrung", + "code": null + }, + { + "id": "katzenzubehor", + "description": "Katzenzubehör", + "url": "https://www.roksh.at//hofer/angebot/tierberdarf/katzenzubehor", + "code": null + }, + { + "id": "katzennahrung", + "description": "Katzennahrung", + "url": "https://www.roksh.at//hofer/angebot/tierberdarf/katzennahrung", + "code": null + }, + { + "id": "joghurt-topfen", + "url": "https://www.roksh.at/hofer/angebot/joghurt-topfen", + "code": "" + }, + { + "id": "milchgetrank", + "url": "https://www.roksh.at/hofer/angebot/milchgetrank", + "code": "" + }, + { + "id": "fruchtjoghurt", + "url": "https://www.roksh.at/hofer/angebot/fruchtjoghurt", + "code": "" + }, + { + "id": "haltbare-milch-sahne-eiskaffee", + "url": "https://www.roksh.at/hofer/angebot/haltbare-milch-sahne-eiskaffee", + "code": "" + }, + { + "id": "milch-sahne-butter", + "url": "https://www.roksh.at/hofer/angebot/milch-sahne-butter", + "code": "" + }, + { + "id": "kasespezialitaten", + "url": "https://www.roksh.at/hofer/angebot/kasespezialitaten", + "code": "" + }, + { + "id": "frischkase-co", + "url": "https://www.roksh.at/hofer/angebot/frischkase-co", + "code": "" + }, + { + "id": "aufstriche-co", + "url": "https://www.roksh.at/hofer/angebot/aufstriche-co", + "code": "" + }, + { + "id": "hart-schnittkase", + "url": "https://www.roksh.at/hofer/angebot/hart-schnittkase", + "code": "" + }, + { + "id": "weichkase", + "url": "https://www.roksh.at/hofer/angebot/weichkase", + "code": "" + }, + { + "id": "kase-geschnitten-gerieben", + "url": "https://www.roksh.at/hofer/angebot/kase-geschnitten-gerieben", + "code": "" + }, + { + "id": "streichwurst-pasteten", + "url": "https://www.roksh.at/hofer/angebot/streichwurst-pasteten", + "code": "" + }, + { + "id": "wurst-geschnitten", + "url": "https://www.roksh.at/hofer/angebot/wurst-geschnitten", + "code": "" + }, + { + "id": "kochschinken", + "url": "https://www.roksh.at/hofer/angebot/kochschinken", + "code": "" + }, + { + "id": "stangenwurst", + "url": "https://www.roksh.at/hofer/angebot/stangenwurst", + "code": "" + }, + { + "id": "wurstel", + "url": "https://www.roksh.at/hofer/angebot/wurstel", + "code": "" + }, + { + "id": "speck-rohschinken", + "url": "https://www.roksh.at/hofer/angebot/speck-rohschinken", + "code": "" + }, + { + "id": "leberkase-co", + "url": "https://www.roksh.at/hofer/angebot/leberkase-co", + "code": "" + }, + { + "id": "faschiertes", + "url": "https://www.roksh.at/hofer/angebot/faschiertes", + "code": "" + }, + { + "id": "schweinefleisch-spezialitaten", + "url": "https://www.roksh.at/hofer/angebot/schweinefleisch-spezialitaten", + "code": "" + }, + { + "id": "hühnchen-geflügel", + "url": "https://www.roksh.at/hofer/angebot/hühnchen-geflügel", + "code": "" + }, + { + "id": "rind", + "url": "https://www.roksh.at/hofer/angebot/rind", + "code": "" + }, + { + "id": "fruchtaufstriche", + "url": "https://www.roksh.at/hofer/angebot/fruchtaufstriche", + "code": "" + }, + { + "id": "honig-nussaufstriche", + "url": "https://www.roksh.at/hofer/angebot/honig-nussaufstriche", + "code": "" + }, + { + "id": "gemusekonserven", + "url": "https://www.roksh.at/hofer/angebot/gemusekonserven", + "code": "" + }, + { + "id": "obstkonserven", + "url": "https://www.roksh.at/hofer/angebot/obstkonserven", + "code": "" + }, + { + "id": "sauerkonserven", + "url": "https://www.roksh.at/hofer/angebot/sauerkonserven", + "code": "" + }, + { + "id": "fleisch-fischkonserven", + "url": "https://www.roksh.at/hofer/angebot/fleisch-fischkonserven", + "code": "" + }, + { + "id": "nusse", + "url": "https://www.roksh.at/hofer/angebot/nusse", + "code": "" + }, + { + "id": "trockenfruchte", + "url": "https://www.roksh.at/hofer/angebot/trockenfruchte", + "code": "" + }, + { + "id": "tafelschokolade", + "url": "https://www.roksh.at/hofer/angebot/tafelschokolade", + "code": "" + }, + { + "id": "schokoriegel", + "url": "https://www.roksh.at/hofer/angebot/schokoriegel", + "code": "" + }, + { + "id": "bonbons-kaugummi", + "url": "https://www.roksh.at/hofer/angebot/bonbons-kaugummi", + "code": "" + }, + { + "id": "kekse", + "url": "https://www.roksh.at/hofer/angebot/kekse", + "code": "" + }, + { + "id": "waffeln", + "url": "https://www.roksh.at/hofer/angebot/waffeln", + "code": "" + }, + { + "id": "fruchtgummi", + "url": "https://www.roksh.at/hofer/angebot/fruchtgummi", + "code": "" + }, + { + "id": "pralinen", + "url": "https://www.roksh.at/hofer/angebot/pralinen", + "code": "" + }, + { + "id": "salzgeback-kracker", + "url": "https://www.roksh.at/hofer/angebot/salzgeback-kracker", + "code": "" + }, + { + "id": "chips", + "url": "https://www.roksh.at/hofer/angebot/chips", + "code": "" + }, + { + "id": "sekt", + "url": "https://www.roksh.at/hofer/angebot/sekt", + "code": "" + }, + { + "id": "roseweine-spezialweine", + "url": "https://www.roksh.at/hofer/angebot/roseweine-spezialweine", + "code": "" + }, + { + "id": "weißweine", + "url": "https://www.roksh.at/hofer/angebot/weißweine", + "code": "" + }, + { + "id": "rotweine", + "url": "https://www.roksh.at/hofer/angebot/rotweine", + "code": "" + }, + { + "id": "tee", + "url": "https://www.roksh.at/hofer/angebot/tee", + "code": "" + }, + { + "id": "kaffee-kakao-co", + "url": "https://www.roksh.at/hofer/angebot/kaffee-kakao-co", + "code": "" + }, + { + "id": "mineralwasser", + "url": "https://www.roksh.at/hofer/angebot/mineralwasser", + "code": "" + }, + { + "id": "softdrinks", + "url": "https://www.roksh.at/hofer/angebot/softdrinks", + "code": "" + }, + { + "id": "sport-energy-drinks", + "url": "https://www.roksh.at/hofer/angebot/sport-energy-drinks", + "code": "" + }, + { + "id": "fruchtsafte", + "url": "https://www.roksh.at/hofer/angebot/fruchtsafte", + "code": "" + }, + { + "id": "smoothies", + "url": "https://www.roksh.at/hofer/angebot/smoothies", + "code": "" + }, + { + "id": "sirupe", + "url": "https://www.roksh.at/hofer/angebot/sirupe", + "code": "" + }, + { + "id": "deodorants", + "url": "https://www.roksh.at/hofer/angebot/deodorants", + "code": "" + }, + { + "id": "zahn-mundhygiene", + "url": "https://www.roksh.at/hofer/angebot/zahn-mundhygiene", + "code": "" + }, + { + "id": "duschpflege-seife", + "url": "https://www.roksh.at/hofer/angebot/duschpflege-seife", + "code": "" + }, + { + "id": "herrenkosmetik-rasur", + "url": "https://www.roksh.at/hofer/angebot/herrenkosmetik-rasur", + "code": "" + }, + { + "id": "intimhygiene", + "url": "https://www.roksh.at/hofer/angebot/intimhygiene", + "code": "" + }, + { + "id": "sonnenpflege", + "url": "https://www.roksh.at/hofer/angebot/sonnenpflege", + "code": "" + }, + { + "id": "haarpflege", + "url": "https://www.roksh.at/hofer/angebot/haarpflege", + "code": "" + }, + { + "id": "beikost-snacks", + "url": "https://www.roksh.at/hofer/angebot/beikost-snacks", + "code": "" + }, + { + "id": "windeln-pflegeprodukte", + "url": "https://www.roksh.at/hofer/angebot/windeln-pflegeprodukte", + "code": "" + }, + { + "id": "milchnahrung", + "url": "https://www.roksh.at/hofer/angebot/milchnahrung", + "code": "" + }, + { + "id": "spulmittel-putzmittel", + "url": "https://www.roksh.at/hofer/angebot/spulmittel-putzmittel", + "code": "" + }, + { + "id": "reinigungstucher-kuchentucher", + "url": "https://www.roksh.at/hofer/angebot/reinigungstucher-kuchentucher", + "code": "" + }, + { + "id": "wc-lufterfrischer", + "url": "https://www.roksh.at/hofer/angebot/wc-lufterfrischer", + "code": "" + }, + { + "id": "waschmittel", + "url": "https://www.roksh.at/hofer/angebot/waschmittel", + "code": "" + } +] diff --git a/stores/hofer.js b/stores/hofer.js index 5520b4e..6cee6e0 100644 --- a/stores/hofer.js +++ b/stores/hofer.js @@ -2,6 +2,7 @@ const fs = require("fs"); const path = require("path"); const axios = require("axios"); const utils = require("./utils"); +const analysis = require("../analysis"); const units = { "": { unit: "stk", factor: 1 }, @@ -86,26 +87,24 @@ exports.getCategories = async () => { exports.urlBase = "https://www.roksh.at/hofer/produkte/"; -exports.initializeCategoryMapping = async () => {}; - -exports.mapCategory = (rawItem) => {}; - -exports.generateCategoryMapping = async (rawItems) => { - const { categories } = await exports.getCategories(); +exports.initializeCategoryMapping = async () => { + // This is unfortunate, but the API doesn't return all categories + const rawItems = analysis.readJSON("data/hofer-2023-06-21.json.br"); // await exports.fetchData(); + const rawCategories = (await exports.getCategories()).categories; const lookup = {}; const processCategory = (category) => { lookup[category.ProgID] = { - category: category.ProgID, - url: category.Url, - code: "", - numItems: 0, + id: category.ProgID, + description: category.CategoryName, + url: "https://www.roksh.at/" + category.Url, + code: null, }; for (const child of category.ChildList) { processCategory(child); } }; - for (const category of categories) { + for (const category of rawCategories) { processCategory(category); } @@ -115,28 +114,17 @@ exports.generateCategoryMapping = async (rawItems) => { console.log(`Couldn't find category '${item.CategorySEOName}' for Hofer product ${item.ProductName}`); total++; lookup[item.CategorySEOName] = { - category: item.CategorySEOName, - url: "", + id: item.CategorySEOName, + url: "https://www.roksh.at/hofer/angebot/" + item.CategorySEOName, code: "", - numItems: 1, }; } else { const category = lookup[item.CategorySEOName]; - category.item = item; - category.numItems++; } } - const output = Object.keys(lookup).map((key) => lookup[key]); - const oldCategories = path.join(__dirname, "hofer-categories.json"); - fs.writeFileSync(path.join(__dirname, "hofer-categories.json"), JSON.stringify(output, null, 2)); + exports.categories = []; + Object.keys(lookup).forEach((key) => exports.categories.push(lookup[key])); + utils.mergeAndSaveCategories("hofer", exports.categories); }; -// Generate JSON for category mapping in stores/hofer-categories.json -if (require.main === module) { - (async () => { - const { readJSON } = require("../analysis"); - // const rawItems = await this.fetchData(); - const rawItems = readJSON("data/hofer-2023-06-20.json.br"); - await exports.generateCategoryMapping(rawItems); - })(); -} +exports.mapCategory = (rawItem) => {}; diff --git a/stores/utils.js b/stores/utils.js index ef833cc..5a2f01c 100644 --- a/stores/utils.js +++ b/stores/utils.js @@ -1,123 +1,6 @@ const fs = require("fs"); const path = require("path"); -// These are a match of the Billa categories, which are organized in a 2-level hierarchy. -// Each category in the top level gets a code from 1-Z, each sub category also gets a code. -// Together the two codes from a unique id for the category, which we store in the item.category -// field. E.g. "Obst & Gemüse > Salate" has the code "13", "Kühlwaren > Tofu" has the code "4C" -exports.globalCategories = [ - { - name: "Obst & Gemüse", - subcategories: ["Obst", "Gemüse", "Salate", "Trockenfrüchte & Nüsse"], - }, - { - name: "Brot & Gebäck", - subcategories: ["Aufbackbrötchen & Toast", "Brot & Gebäck", "Knäckebrot & Zwieback", "Kuchen & Co.", "Semmelwürfel & Brösel"], - }, - { - name: "Getränke", - subcategories: ["Alkoholfreie Getränke", "Bier & Radler", "Kaffee, Tee & Co.", "Sekt & Champagner", "Spirituosen", "Wein", "Mineralwasser"], - }, - { - name: "Kühlwaren", - subcategories: [ - "Schnelle Küche", - "Eier", - "Fleisch", - "Käse, Aufstriche & Salate", - "Milchprodukte", - "Feinkostplatten & Brötchen", - "Blätterteig, Strudelteig", - "Wurst, Schinken & Speck", - "Feinkost", - "Fisch", - "Unbekannt", // Not available in Billa hierarchy, left blank - "Tofu", - ], - }, - { - name: "Tiefkühl", - subcategories: [ - "Eis", - "Unbekannt", // Not available in Billa hierarchy, left blank - "Fertiggerichte", - "Fisch & Garnelen", - "Gemüse & Kräuter", - "Pommes Frites & Co.", - "Pizza & Baguette", - "Desserts & Früchte", - ], - }, - { - name: "Grundnahrungsmittel", - subcategories: [ - "Asia & Mexican Produkte", - "Baby", - "Backen", - "Essig & Öl", - "Fertiggerichte", - "Gewürze & Würzmittel", - "Honig, Marmelade & Co.", - "Konserven & Sauerwaren", - "Kuchen & Co.", - "Mehl & Getreideprodukte", - "Müsli & Cerealien", - "Reis, Teigwaren & Sugo", - "Saucen & Dressings", - "Spezielle Ernährung", - "Zucker & Süßstoffe", - "Fixprodukte", - ], - }, - { - name: "Süßes & Salziges", - subcategories: ["Biskotten & Eiswaffeln", "Für kluge Naschkatzen", "Müsliriegel", "Chips & Co.", "Süßes"], - }, - { - name: "Pflege", - subcategories: [ - "Baby", - "Damenhygiene", - "Deodorants", - "Haarpflege & Haarfarben", - "Pflaster & Verbandsmaterial", - "Haut- & Lippenpflege", - "Mund- & Zahnhygiene", - "Rasierbedarf", - "Seife & Duschbäder", - "Sonnen- & Gelsenschutzmittel", - "Verhütungsmittel", - "Fußpflege", - "Strumpfhosen & Socken", - ], - }, - { - name: "Haushalt", - subcategories: [ - "Büro- & Schulartikel", - "Garten", - "Kleben & Befestigen", - "Küchenartikel", - "Küchenrollen & WC-Papier", - "Lampen & Batterien", - "Müllsäcke, Gefrierbeutel & Co.", - "Raumsprays & Kerzen", - "Reinigen & Pflegen", - "Taschentücher & Servietten", - "Waschmittel & Weichspüler", - "Schuhpflege", - "Kunststoffbehälter", - "Insektenschutz", - "Spielwaren", - "Hygiene-Schutzartikel", - ], - }, - { - name: "Haustier", - subcategories: ["Hunde", "Katzen", "Nager", "Vögel"], - }, -]; - exports.mergeAndSaveCategories = (store, categories) => { const mappingFile = path.join(__dirname, `${store}-categories.json`); if (fs.existsSync(mappingFile)) {