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

71 lines • 2.85 kB
import { importGtfs } from 'gtfs'; import { readFile } from 'fs/promises'; import path from 'node:path'; import { GTFSQueries } from './queries.js'; async function main() { try { console.log('šŸš€ Starting GTFS UK BODS data processing...'); // Load configuration const configPath = path.resolve('./src/config.json'); const configData = await readFile(configPath, 'utf8'); const config = JSON.parse(configData); console.log('šŸ“ Configuration loaded:', config); // Import GTFS data console.log('šŸ“„ Importing GTFS data into SQLite database...'); console.log('ā³ This may take several minutes for large datasets...'); await importGtfs(config); console.log('āœ… GTFS data imported successfully!'); console.log(`šŸ“Š Database created at: ${config.sqlitePath}`); // Query some basic statistics await displayStats(); } catch (error) { console.error('āŒ Error processing GTFS data:', error); process.exit(1); } } async function displayStats() { try { console.log('\nšŸ“ˆ Displaying database statistics...'); // Get agencies const agencies = await GTFSQueries.getAllAgencies(); console.log(`šŸ¢ Total agencies: ${agencies.length}`); if (agencies.length > 0) { console.log('šŸ“‹ Agencies:'); agencies.forEach((agency, index) => { console.log(` ${index + 1}. ${agency.agency_name} (${agency.agency_id})`); }); } // Get routes const routes = await GTFSQueries.getAllRoutes(); console.log(`🚌 Total routes: ${routes.length}`); // Get stops const stops = await GTFSQueries.getAllStops(); console.log(`šŸš Total stops: ${stops.length}`); // Display sample routes if (routes.length > 0) { console.log('\nšŸ” Sample routes:'); const sampleRoutes = routes.slice(0, 5); sampleRoutes.forEach((route, index) => { console.log(` ${index + 1}. ${route.route_short_name || route.route_id}: ${route.route_long_name || 'No description'}`); }); } // Display sample stops if (stops.length > 0) { console.log('\nšŸ” Sample stops:'); const sampleStops = stops.slice(0, 5); sampleStops.forEach((stop, index) => { console.log(` ${index + 1}. ${stop.stop_name} (${stop.stop_id}) - Lat: ${stop.stop_lat}, Lon: ${stop.stop_lon}`); }); } } catch (error) { console.error('āŒ Error retrieving statistics:', error); } } // Run the main function if (import.meta.url === `file://${process.argv[1]}`) { main(); } export { main, displayStats }; //# sourceMappingURL=index.js.map