← back to Wolfgordon Crawl
deleted-audit.js
30 lines
const https=require('https');
const {pool,closePool}=require('./scraper-utils');
const UA='Mozilla/5.0 Chrome/120';
function probe(handle){return new Promise(res=>{
const u=`https://www.designerwallcoverings.com/products/${handle}.js`;
https.get(u,{timeout:15000,headers:{'User-Agent':UA}},r=>{
let d='';r.on('data',c=>d+=c);r.on('end',()=>{
if(r.statusCode!==200) return res({live:false,code:r.statusCode});
try{const j=JSON.parse(d);res({live:true,avail:j.available,price:(j.variants&&j.variants[0]?j.variants[0].price/100:null)});}
catch{res({live:false,code:'nojson'});}
});
}).on('error',()=>res({live:false,code:'err'})).on('timeout',function(){this.destroy();res({live:false,code:'timeout'});});
});}
(async()=>{
// random sample of deleted rows that have a handle
const {rows}=await pool.query("SELECT dw_sku, handle FROM shopify_products WHERE status='DELETED_FROM_SHOPIFY' AND handle IS NOT NULL AND handle<>'' ORDER BY random() LIMIT 80");
console.log(`Probing ${rows.length} sampled 'deleted' rows against live Shopify...`);
let live=0,dead=0,i=0; const liveSamples=[];
const conc=6;
async function worker(){ while(i<rows.length){ const r=rows[i++]; const res=await probe(r.handle);
if(res.live){live++; if(liveSamples.length<10) liveSamples.push(`${r.dw_sku} $${res.price} avail=${res.avail}`);} else dead++;
}}
await Promise.all(Array.from({length:conc},worker));
console.log(`\n=== RESULT (sample of ${rows.length}) ===`);
console.log(`ACTUALLY LIVE (mirror wrong): ${live} (${(live/rows.length*100).toFixed(0)}%)`);
console.log(`Confirmed gone: ${dead}`);
console.log('live examples:'); liveSamples.forEach(s=>console.log(' '+s));
await closePool();
})().catch(e=>{console.error(e);closePool();});