Files
ScraperControl/scripts/import-hk-parishes.ts

59 lines
1.7 KiB
TypeScript
Raw Normal View History

#!/usr/bin/env tsx
/**
* Import HK Diocese parish directory from plain-text paste.
* Usage: npx tsx scripts/import-hk-parishes.ts [--dry-run] [--file scripts/hk-parishes.txt]
*/
import dotenv from 'dotenv';
import path from 'path';
import fs from 'fs';
dotenv.config({ path: path.resolve(process.cwd(), '.env.local') });
dotenv.config({ path: path.resolve(process.cwd(), '.env') });
import { Pool } from 'pg';
import { PrismaPg } from '@prisma/adapter-pg';
import { PrismaClient } from '@prisma/client';
const dbUrl = process.env.DATABASE_URL || 'postgresql://postgres:postgres@localhost:5432/nearestmass';
console.log(`Connecting to database: ${dbUrl.replace(/:[^:@]+@/, ':***@')}`);
const pool = new Pool({
connectionString: dbUrl,
ssl: dbUrl.includes('neon') ? { rejectUnauthorized: false } : undefined,
});
const adapter = new PrismaPg(pool);
const prisma = new PrismaClient({ adapter });
// ─── Types ────────────────────────────────────────────────────────────────────
export interface ParsedSchedule {
dayOfWeek: number; // 0=Sun, 1=Mon, ..., 6=Sat
time: string; // "HH:MM"
language: string; // "English" | "Cantonese" | "Tagalog"
notes: string | null;
}
export interface ParsedEntry {
locationName: string;
parishName: string | null;
address: string | null;
phone: string | null;
email: string | null;
schedules: ParsedSchedule[];
}
interface ExistingChurch {
id: string;
name: string;
address: string | null;
phone: string | null;
email: string | null;
}
interface ImportStats {
matched: number;
created: number;
schedulesWritten: number;
skipped: number;
}