UNPKG

gtfs-bods

Version:

A CLI tool for processing UK Bus Open Data Service (BODS) GTFS data - import, export, and query transit data with ease

38 lines 1.65 kB
import { importGtfs } from 'gtfs'; import { readFile } from 'fs/promises'; import path from 'node:path'; async function importData() { try { console.log('🚀 Starting GTFS import process...'); // Load configuration const configPath = process.env.CONFIG_PATH || path.resolve('./src/config.json'); const configData = await readFile(configPath, 'utf8'); const config = JSON.parse(configData); console.log('📁 Configuration loaded from:', configPath); console.log('📦 Agencies to import:', config.agencies.length); config.agencies.forEach((agency, index) => { console.log(` ${index + 1}. ${agency.agency_key}: ${agency.path}`); }); console.log(`🗄️ Database will be created at: ${config.sqlitePath}`); // Import GTFS data console.log('📥 Starting import...'); console.log('⏳ This process may take several minutes for large GTFS files...'); const startTime = Date.now(); await importGtfs(config); const endTime = Date.now(); const duration = Math.round((endTime - startTime) / 1000); console.log('✅ GTFS import completed successfully!'); console.log(`⏱️ Import took ${duration} seconds`); console.log(`📊 SQLite database created at: ${path.resolve(config.sqlitePath)}`); } catch (error) { console.error('❌ Error during GTFS import:', error); process.exit(1); } } // Run the import function if (import.meta.url === `file://${process.argv[1]}`) { importData(); } export { importData }; //# sourceMappingURL=import.js.map