from datetime import datetime, date, time, timedelta def hms_to_seconds(hms_str): """Converts GTFS 'HH:MM:SS' (e.g. '25:30:00') to total seconds from midnight.""" h, m, s = map(int, hms_str.split(':')) return (h * 3600) + (m * 60) + s def get_service_day_start_ts(): """ Returns the Unix timestamp for 00:00:00 of the CURRENT service day. TTC service day typically flips at 4:00 AM. """ now = datetime.now() # If it's 2 AM, we are still technically on 'yesterday's' schedule if now.hour < 4: service_date = date.today() - timedelta(days=1) else: service_date = date.today() # Combine that date with 00:00:00 and get the timestamp service_start_dt = datetime.combine(service_date, time.min) return int(service_start_dt.timestamp()) def translate_occupancy(status): """Maps GTFS occupancy enums to human readable strings.""" mapping = { 0: "Empty", 1: "Many Seats Available", 2: "Few Seats Available", 3: "No Seats Available", 5: "Full", 6: "Not In Service" } return mapping.get(status, "Full") # when in doubt assume the bus is full