'use strict'; const https = require('https'); function get(url) { return new Promise((res, rej) => { https.get(url, { headers: { 'User-Agent': 'Mozilla/5.0 Chrome/120.0', 'Accept': 'application/json' } }, r => { let d = ''; r.on('data', c => d += c); r.on('end', () => { try { res(JSON.parse(d)); } catch (e) { res(null); } }); }).on('error', () => res(null)).setTimeout(15000); }); } const STORE_CONFIGS = { jumbo: { host: 'www.jumbo.com.ar', cats: ['almacen','bebidas','frutas-y-verduras','carnes','lacteos','congelados','limpieza','mascotas'] }, disco: { host: 'www.disco.com.ar', cats: ['almacen','bebidas','frutas-y-verduras','carnes','lacteos','congelados','limpieza'] }, carrefour: { host: 'www.carrefour.com.ar', cats: ['almacen','bebidas','frutas-y-verduras','carnes','lacteos','congelados','limpieza'] }, changomas: { host: 'www.masonline.com.ar', cats: ['almacen','bebidas','frutas-y-verduras','carnes','lacteos','congelados','limpieza'] }, }; const PROMO_PATTERN = /\d+\s*%|\d+x\d+|2do|3ro|segunda|gratis|descuento|oferta|\d+\s*csi|ahorro|hasta|llevate|2\s*al|3\s*al/i; async function findPromoClusters(storeName, { host, cats }) { const clusterMap = new Map(); for (const cat of cats) { const url = `https://${host}/_v/api/intelligent-search/product_search?page=1&count=50&selectedFacets=[{"key":"category-1","value":"${cat}"}]`; const j = await get(url); for (const p of (j?.products || [])) { for (const c of (p.clusterHighlights || [])) { if (c && c.id && !clusterMap.has(c.id)) clusterMap.set(c.id, c.name || ''); } for (const c of (p.productClusters || [])) { if (c && c.id && !clusterMap.has(c.id)) clusterMap.set(c.id, c.name || ''); } } process.stdout.write('.'); } console.log(); const promo = [...clusterMap.entries()].filter(([id, name]) => PROMO_PATTERN.test(name)); console.log(`${storeName}: ${clusterMap.size} total clusters, ${promo.length} promo clusters`); promo.slice(0, 15).forEach(([id, name]) => console.log(` [${id}] ${name}`)); return promo; } (async () => { for (const [name, cfg] of Object.entries(STORE_CONFIGS)) { process.stdout.write(`\n[${name}] scanning categories `); try { await findPromoClusters(name, cfg); } catch (e) { console.log(`ERROR: ${e.message}`); } } })();