← back to Nationalrealestate

src/ingest/parcels/engine.ts

51 lines

/**
 * Parcel-ingest dispatcher: npm run ingest:parcels <county>
 * Counties: nyc (five boroughs, PLUTO) | nyc-acris (ACRIS deed sales onto PLUTO)
 *           | king (King WA EXTR) | cook (Cook IL Socrata)
 * Per-county adapters own download + parse + upsert + parcel_source registration.
 */
import { pool } from '../../../db/pool.ts';

const ADAPTERS: Record<string, () => Promise<{ run: () => Promise<{ upserted: number }> }>> = {
  nyc: async () => ({ run: (await import('./nyc_pluto.ts')).ingestNycPluto }),
  'nyc-acris': async () => ({ run: (await import('./nyc_acris.ts')).ingestNycAcris }),
  king: async () => ({ run: (await import('./king_wa.ts')).ingestKing }),
  cook: async () => ({ run: (await import('./cook_il.ts')).ingestCook }),
  franklin: async () => ({ run: (await import('./franklin_oh.ts')).ingestFranklin }),
  miami: async () => ({ run: (await import('./miami_dade.ts')).ingestMiami }),
  wake: async () => ({ run: (await import('./wake_nc.ts')).ingestWake }),
  tarrant: async () => ({ run: (await import('./tarrant_tx.ts')).ingestTarrant }),
  bexar: async () => ({ run: (await import('./bexar_tx.ts')).ingestBexar }),
  fulton: async () => ({ run: (await import('./fulton_ga.ts')).ingestFulton }),
  saltlake: async () => ({ run: (await import('./saltlake_ut.ts')).ingestSaltLake }),
  sandiego: async () => { const m = await import('./sandiego_ca.ts'); return { run: () => m.ingestSanDiego('poway') }; },
  'sandiego-county': async () => { const m = await import('./sandiego_ca.ts'); return { run: () => m.ingestSanDiego('county') }; },
  'oregon-rlis': async () => { const m = await import('./arcgis_sales.ts'); return { run: m.ingestArcgisSales('oregon-rlis') }; },
  spokane: async () => { const m = await import('./arcgis_sales.ts'); return { run: m.ingestArcgisSales('spokane') }; },
  alameda: async () => { const m = await import('./arcgis_sales.ts'); return { run: m.ingestArcgisSales('alameda') }; },
  deschutes: async () => { const m = await import('./arcgis_sales.ts'); return { run: m.ingestArcgisSales('deschutes') }; },
  crook: async () => { const m = await import('./arcgis_sales.ts'); return { run: m.ingestArcgisSales('crook') }; },
  sonoma: async () => { const m = await import('./arcgis_sales.ts'); return { run: m.ingestArcgisSales('sonoma') }; },
  colorado: async () => { const m = await import('./arcgis_sales.ts'); return { run: m.ingestArcgisSales('colorado') }; },
  maricopa: async () => { const m = await import('./arcgis_sales.ts'); return { run: m.ingestArcgisSales('maricopa') }; },
  thurston: async () => { const m = await import('./arcgis_sales.ts'); return { run: m.ingestArcgisSales('thurston') }; },
  'palm-beach': async () => { const m = await import('./arcgis_sales.ts'); return { run: m.ingestArcgisSales('palm-beach') }; },
  klamath: async () => { const m = await import('./arcgis_sales.ts'); return { run: m.ingestArcgisSales('klamath') }; },
  marion: async () => { const m = await import('./arcgis_sales.ts'); return { run: m.ingestArcgisSales('marion') }; },
  yakima: async () => { const m = await import('./arcgis_sales.ts'); return { run: m.ingestArcgisSales('yakima') }; },
};

async function main() {
  const which = (process.argv[2] || '').toLowerCase();
  if (!ADAPTERS[which]) {
    console.error(`usage: npm run ingest:parcels -- <${Object.keys(ADAPTERS).join('|')}>`);
    process.exit(2);
  }
  const { run } = await ADAPTERS[which]();
  const { upserted } = await run();
  console.log(`[parcels:${which}] done, ${upserted} upserted`);
  await pool.end();
}

main().catch(e => { console.error(e); process.exit(1); });