--- a/service.py Mon Mar 05 12:47:40 2018 +0200 +++ b/service.py Mon Mar 05 12:56:42 2018 +0200 @@ -81,10 +81,10 @@ else: return schedule_entry['trip'].schedule[-1].stop.name -def long_form_sign(schedule_entry): +def long_form_sign(schedule_entry, long = True): from math import ceil trip_length = schedule_entry['trip'].length - schedule_entry['stop'].traveled_distance - sign = reduce_schedule(schedule_entry['trip'].concise_schedule(schedule_entry['stop']), trip_length = trip_length, long = True) + sign = reduce_schedule(schedule_entry['trip'].concise_schedule(schedule_entry['stop']), trip_length = trip_length, long = long) if sign: return { 'destination': tr(sign[-1], 'places'), @@ -274,6 +274,13 @@ 'abbreviation': trip_abbreviation(trip), }) +def current_bus_day(): + from datetime import date, datetime, timedelta + day = date.today() + if datetime.now().hour < 5: + day -= timedelta(1) + return day + @app.route('/stop_display/<reference>') def stop_display(reference): from buses import bus_stops @@ -282,12 +289,12 @@ bus_stop = bus_stops[reference] except KeyError: abort(404) - for i, schedule_entry in enumerate(bus_stop.schedule_for_day(today(), arrivals = False)): + for i, schedule_entry in enumerate(bus_stop.schedule_for_day(current_bus_day(), arrivals = False)): schedule.append({ 'time_data': schedule_entry['time'], 'time': time_representation(schedule_entry['time']), 'route': schedule_entry['trip'].route.reference, - 'sign': long_form_sign(schedule_entry), + 'sign': long_form_sign(schedule_entry, long = False), 'trip': schedule_entry['stop'].trip.name, 'night': is_night_time(schedule_entry['time']), 'imminent': imminent(schedule_entry),