← back to Dw Marketing Reels
data/fetch-collection-products.mjs
20 lines
import fs from 'node:fs';
const handle=process.argv[2], out=process.argv[3];
const get=(u)=>fetch(u,{headers:{'User-Agent':'Mozilla/5.0'}}).then(r=>r.json());
let all=[],page=1;
while(page<=6){
const j=await get(`https://www.designerwallcoverings.com/collections/${handle}/products.json?limit=250&page=${page}&sort_by=created-descending`).catch(()=>({}));
const ps=j.products||[]; if(!ps.length)break; all.push(...ps); page++;
}
const rows=all.map(p=>{
const imgs=(p.images||[]).map(i=>({url:i.src,w:i.width,h:i.height}));
if(!imgs.length)return null;
const room=imgs.length>1?imgs.slice(1).reduce((b,im)=>(im.w*im.h>b.w*b.h?im:b)):null;
const title=p.title.replace(/ \| .*$/,'').replace(/ Wallcovering$/,'').trim();
return {title,handle:p.handle,url:`https://www.designerwallcoverings.com/products/${p.handle}`,
image:imgs[0].url,room:(room||imgs[0]).url,has_room:!!room,chapter:'all'};
}).filter(Boolean);
fs.writeFileSync(out,JSON.stringify(rows,null,2));
console.log(`${handle}: ${rows.length} products (${rows.filter(r=>r.has_room).length} real rooms)`);
console.log('newest:',rows.slice(0,4).map(r=>r.title).join(' | '));