#!/usr/bin/env ts-node /** * Helper script to find Stop IDs and Route IDs * Usage: * npm run find -- --stop "american" * npm run find -- --route "7" */ import { loadGtfsStops, loadGtfsRoutes } from './lib/gtfs'; function parseArgs() { const args = process.argv.slice(2); let searchStop = ''; let searchRoute = ''; for (let i = 0; i < args.length; i++) { if (args[i] === '--stop' && args[i + 1]) { searchStop = args[i + 1].toLowerCase(); i++; } else if (args[i] === '--route' && args[i + 1]) { searchRoute = args[i + 1].toLowerCase(); i++; } else if (args[i] === '--help' || args[i] === '-h') { console.log(` Usage: npm run find -- [options] Options: --stop Search for stops by name (case-insensitive) --route Search for routes by name or number --help, -h Show this help message Examples: npm run find -- --stop "american" npm run find -- --route "7" npm run find -- --stop "center" npm run find -- --route "linija" `); process.exit(0); } } return { searchStop, searchRoute }; } async function main() { const { searchStop, searchRoute } = parseArgs(); if (!searchStop && !searchRoute) { console.log('Please specify --stop or --route. Use --help for usage information.'); process.exit(1); } console.log('Loading GTFS data...\n'); const stops = loadGtfsStops(); const routes = loadGtfsRoutes(); if (searchStop) { console.log(`=== Searching for stops matching "${searchStop}" ===\n`); const matches = Array.from(stops.values()) .filter(stop => stop.stop_name.toLowerCase().includes(searchStop)) .slice(0, 20); // Limit to 20 results if (matches.length === 0) { console.log('No stops found.'); } else { console.log(`Found ${matches.length} stop(s):\n`); matches.forEach(stop => { console.log(`Stop ID: ${stop.stop_id}`); console.log(` Name: ${stop.stop_name}`); console.log(` Code: ${stop.stop_code}`); console.log(` Location: ${stop.stop_lat}, ${stop.stop_lon}`); console.log(''); }); if (matches.length === 20) { console.log('(Showing first 20 results, refine your search for more specific results)\n'); } } } if (searchRoute) { console.log(`=== Searching for routes matching "${searchRoute}" ===\n`); const matches = Array.from(routes.values()) .filter(route => route.route_short_name?.toLowerCase().includes(searchRoute) || route.route_long_name?.toLowerCase().includes(searchRoute) ) .slice(0, 20); // Limit to 20 results if (matches.length === 0) { console.log('No routes found.'); } else { console.log(`Found ${matches.length} route(s):\n`); matches.forEach(route => { console.log(`Route ID: ${route.route_id}`); console.log(` Number: ${route.route_short_name}`); console.log(` Name: ${route.route_long_name}`); console.log(''); }); if (matches.length === 20) { console.log('(Showing first 20 results, refine your search for more specific results)\n'); } } } console.log('Use these IDs in the web interface or terminal tracker.'); } main();