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

51 lines 1.94 kB
import { exportGtfs } from 'gtfs'; import { readFile } from 'fs/promises'; import path from 'node:path'; async function exportData() { try { console.log('🚀 Starting GTFS export process...'); // Check if config path is provided via environment variable const configPath = process.env.CONFIG_PATH; let exportConfig; if (configPath) { console.log('📁 Loading export configuration from:', configPath); const configData = await readFile(configPath, 'utf8'); exportConfig = JSON.parse(configData); } else { // Create default export configuration exportConfig = { agencies: [ { agency_key: "uk-bods" } ], sqlitePath: "./gtfs.db", exportPath: "./exported-gtfs", verbose: true }; } console.log('📁 Export configuration:', exportConfig); console.log(`🗄️ Reading from database: ${exportConfig.sqlitePath}`); console.log(`📤 Exporting to: ${exportConfig.exportPath}`); // Export GTFS data console.log('📤 Starting export...'); const startTime = Date.now(); await exportGtfs(exportConfig); const endTime = Date.now(); const duration = Math.round((endTime - startTime) / 1000); console.log('✅ GTFS export completed successfully!'); console.log(`⏱️ Export took ${duration} seconds`); console.log(`📁 GTFS files exported to: ${path.resolve(exportConfig.exportPath)}`); } catch (error) { console.error('❌ Error during GTFS export:', error); process.exit(1); } } // Run the export function if (import.meta.url === `file://${process.argv[1]}`) { exportData(); } export { exportData }; //# sourceMappingURL=export.js.map