All checks were successful
Deploy production / deploy (push) Successful in 2m33s
26 lines
1.0 KiB
TypeScript
26 lines
1.0 KiB
TypeScript
// (Re)computes Leefbaarometer scores for house.listings. The nightly scrape, the CLI and the
|
|
// page already score new and changed listings; this is for backfills and a new LBM year.
|
|
//
|
|
// bun --env-file=$HOME/.config/house-scrape.env scripts/house-liveability.ts [--force] [--id 12]
|
|
import postgres from 'postgres';
|
|
import { scoreListings } from '../src/lib/house-tracker/liveability';
|
|
|
|
const args = process.argv.slice(2);
|
|
const dbUrl = process.env.DB_URL ?? process.env.DATABASE_URL;
|
|
if (!dbUrl) throw new Error('DB_URL is not set');
|
|
const sql = postgres(dbUrl, { max: 1, connect_timeout: 10, onnotice: () => {} });
|
|
const ids = args.includes('--id') ? [Number(args[args.indexOf('--id') + 1])] : undefined;
|
|
try {
|
|
const result = await scoreListings(sql, {
|
|
ids,
|
|
force: args.includes('--force'),
|
|
log: (line) => console.log(line)
|
|
});
|
|
console.log(
|
|
`liveability: ${result.checked} checked, ${result.scored} scored, ${result.notFound} without a location, ${result.failed} failed`
|
|
);
|
|
if (result.failed) process.exitCode = 1;
|
|
} finally {
|
|
await sql.end();
|
|
}
|