Files
ScraperControl/scripts/debug/export-from-nas.ts

61 lines
1.9 KiB
TypeScript
Raw Permalink Normal View History

#!/usr/bin/env tsx
/**
* Export churches from NAS database to JSON
* Run this ON THE NAS (uses DATABASE_URL from .env)
*/
import { PrismaClient } from '@prisma/client';
import fs from 'fs/promises';
async function main() {
const country = process.argv[2] || 'PL';
console.log(`📦 Exporting ${country} data from database...`);
console.log(`DATABASE_URL: ${process.env.DATABASE_URL?.replace(/:[^:@]+@/, ':****@')}`);
const prisma = new PrismaClient();
try {
await prisma.$connect();
console.log('✅ Connected to database');
// Export churches with all schedules
const churches = await prisma.churches.findMany({
where: { country },
include: {
massSchedules: true,
confessionSchedules: true,
adorationSchedules: true,
}
});
console.log(`Found ${churches.length} churches in ${country}`);
// Count schedules
const massSchedules = churches.reduce((sum, c) => sum + (c.massSchedules?.length || 0), 0);
const confessionSchedules = churches.reduce((sum, c) => sum + (c.confessionSchedules?.length || 0), 0);
const adorationSchedules = churches.reduce((sum, c) => sum + (c.adorationSchedules?.length || 0), 0);
// Save to file
const exportFile = `export-${country}.json`;
await fs.writeFile(exportFile, JSON.stringify(churches, null, 2));
console.log(`\n✅ Exported to ${exportFile}`);
console.log(` - ${churches.length} churches`);
console.log(` - ${massSchedules} mass schedules`);
console.log(` - ${confessionSchedules} confession schedules`);
console.log(` - ${adorationSchedules} adoration schedules`);
console.log(`\nDownload with:`);
console.log(` scp albert@192.168.0.145:/volume1/docker/nearestmass/${exportFile} .`);
await prisma.$disconnect();
} catch (error) {
console.error('❌ Export failed:', error);
await prisma.$disconnect();
process.exit(1);
}
}
main().catch(console.error);