feat: add HK parish import script skeleton
- Imports, types, and Prisma client init - ParsedSchedule and ParsedEntry types for parsing parish data - ExistingChurch interface for matching - ImportStats interface for tracking progress Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
58
scripts/import-hk-parishes.ts
Normal file
58
scripts/import-hk-parishes.ts
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
#!/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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user