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
JavaScript
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