--- a/service.py Wed Dec 06 22:47:45 2017 +0200 +++ b/service.py Thu Dec 07 16:55:44 2017 +0200 @@ -268,7 +268,7 @@ bus_stop = bus_stops[reference] except KeyError: abort(404) - for i, schedule_entry in enumerate(bus_stop.schedule_for_day(today(), arrivals = False)[:6]): + for i, schedule_entry in enumerate(bus_stop.schedule_for_day(today(), arrivals = False)): schedule.append({ 'time_data': schedule_entry['time'], 'time': time_representation(schedule_entry['time']), @@ -281,6 +281,17 @@ }) from pprint import pprint pprint(schedule) + def destination_key(schedule_entry): + sign = schedule_entry['sign'] + return (sign['destination'],) + tuple(sign['via']) + def filter_schedule(schedule, *, key): + used = set() + for schedule_entry in schedule: + key_value = key(schedule_entry) + if key_value not in used: + used.add(key_value) + yield schedule_entry + schedule = list(filter_schedule(schedule, key = destination_key))[:6] if schedule: num_imminent_leaves = max(1, len([schedule_entry for schedule_entry in schedule if schedule_entry['time_data'] - schedule[0]['time_data'] < timedelta(minutes = 3)])) else: