← back to Govarbitrage

scripts/import-gsa.ts

32 lines

// Import live GSA Auctions API listings into GovArbitrage (real federal-surplus
// data — no scraping). Runs the deterministic research/cost/scoring pipeline
// (heuristic/local; the worker can AI-enrich later).
//
// Usage: npx tsx scripts/import-gsa.ts [limit]   (default 40)

import { fetchGsaAuctions } from "../src/importers/gsa";
import { ingestMany } from "../src/importers/ingest";
import { prisma } from "../src/lib/db";

async function main() {
  const limit = Number(process.argv[2] || 40);
  console.log(`Fetching live GSA auctions (limit ${limit})…`);
  const rows = await fetchGsaAuctions({ limit, onlyOpen: false });
  console.log(`Fetched ${rows.length} listings. Ingesting + scoring…`);

  const results = await ingestMany(rows, { useAI: false });
  const created = results.filter((r) => r.ok && r.created).length;
  const updated = results.filter((r) => r.ok && !r.created).length;
  const failed = results.filter((r) => !r.ok);

  console.log(`Done: ${created} created, ${updated} updated, ${failed.length} failed.`);
  if (failed.length) failed.slice(0, 5).forEach((f) => console.log(`  ✗ ${f.title}: ${f.error}`));
  await prisma.$disconnect();
}

main().catch(async (e) => {
  console.error("[import-gsa] ERROR:", e.message);
  await prisma.$disconnect();
  process.exit(1);
});