← back to Rentv Website
pull-la-commercial.mjs
23 lines
// Pull the LA commercial digest from the usrealestate backend into data/la-commercial.json.
// Same pattern as the markets pull: an external fetch -> a JSON file RENTV serves.
// USRE_URL (default local :9913; prod = https://usrealestate.agentabrams.com)
// USRE_AUTH (default admin:DW2024! — usrealestate is basic-auth gated)
import fs from 'node:fs';
import path from 'node:path';
const BASE = process.env.USRE_URL || 'http://127.0.0.1:9913';
const AUTH = 'Basic ' + Buffer.from(process.env.USRE_AUTH || 'admin:DW2024!').toString('base64');
const OUT = path.join(process.cwd(), 'data', 'la-commercial.json');
try {
const res = await fetch(BASE + '/api/commercial/digest', { headers: { authorization: AUTH }, signal: AbortSignal.timeout(20000) });
if (!res.ok) throw new Error('HTTP ' + res.status);
const d = await res.json();
if (!d.marquee?.length) throw new Error('empty digest');
fs.writeFileSync(OUT, JSON.stringify(d));
console.log(`[la-commercial] wrote ${d.marquee.length} marquee, ${d.recent.length} recent, ${d.firms.length} firms`);
} catch (e) {
console.error('[la-commercial] pull failed:', e.message);
process.exit(1);
}