← back to Fineartamerica Price Sync
bin/faa-fill-gaps.js
45 lines
#!/usr/bin/env node
// Fill any still-uncached FAA configs by seeding sessions from a set of
// varied-aspect artwork pages. Framed cost is artwork-independent, so whichever
// seed artwork natively offers a given size returns that size's (correct) cost.
// Odd-aspect sizes (24x30, 32x40, 26x48…) aren't in the 7x8 ladder, so we need
// landscape/other-aspect seeds to reach them.
const fs = require('fs');
const { openSession, priceFramedConfig } = require('../lib/faa-http');
const { parseSku, configKey, configLabel } = require('../lib/parse-sku');
const { loadCache, saveCache } = require('../lib/faa-cost');
const { listFaaProducts } = require('../lib/shopify');
const SEEDS = [
'https://fineartamerica.com/featured/3-george-washington-steve-abrams.html',
...fs.readFileSync(__dirname + '/../data/seed-urls.txt', 'utf8').trim().split('\n').filter(Boolean),
];
(async () => {
const ps = await listFaaProducts();
const cache = loadCache();
// distinct missing configs
const missing = new Map();
for (const p of ps) for (const v of p.variants) {
const c = parseSku(v.sku); if (!c) continue;
if (cache[configKey(c)] == null) missing.set(configKey(c), c);
}
console.log(`${missing.size} distinct configs still missing; sweeping ${SEEDS.length} seed artworks`);
for (const url of SEEDS) {
if (missing.size === 0) break;
let s; try { s = await openSession(url); } catch { console.log(' seed fail', url); continue; }
if (!s.sessionId) { console.log(' no session from', url.split('/').pop()); continue; }
let got = 0;
for (const [k, c] of [...missing]) {
const cost = await priceFramedConfig(s, c);
if (cost != null) { cache[configKey(c)] = cost; missing.delete(k); got++; }
}
console.log(` ${url.split('/').pop().replace('.html','')}: filled ${got}, ${missing.size} left`);
saveCache(cache);
}
console.log(`\ndone. ${missing.size} configs still unpriced.`);
if (missing.size) for (const c of missing.values()) console.log(' UNPRICED', configLabel(c));
})().catch(e => { console.error(e); process.exit(1); });