real_time_stop_display.py

Mon, 05 Mar 2018 12:56:42 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Mon, 05 Mar 2018 12:56:42 +0200
changeset 85
62e753b7d3ff
parent 72
65408ed066b3
permissions
-rw-r--r--

things

72
65408ed066b3 Refactor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
1 import buses
65408ed066b3 Refactor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
2 from configparser import ConfigParser
65408ed066b3 Refactor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
3 profile = ConfigParser()
65408ed066b3 Refactor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
4 profile.read('profiles/föli.ini')
65408ed066b3 Refactor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
5 buses.load_buses('gtfs.zip', profile)
65408ed066b3 Refactor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
6
65408ed066b3 Refactor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
7 def service_start_time():
65408ed066b3 Refactor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
8 from datetime import date, datetime, timedelta
65408ed066b3 Refactor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
9 result = datetime.now().replace(hour = 0, minute = 0, second = 0, microsecond = 0)
65408ed066b3 Refactor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
10 if datetime.now().hour < 4:
65408ed066b3 Refactor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
11 result -= timedelta(1)
65408ed066b3 Refactor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
12 return result
65408ed066b3 Refactor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
13
65408ed066b3 Refactor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
14 def find_halt(data, stop_reference):
65408ed066b3 Refactor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
15 from datetime import datetime
65408ed066b3 Refactor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
16 info = (data['blockref'], datetime.fromtimestamp(data['originaimeddeparturetime']) - service_start_time())
65408ed066b3 Refactor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
17 trip = buses.trips_by_vehicle_info[info]
65408ed066b3 Refactor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
18 return [halt for halt in buses.trips_by_vehicle_info[info].schedule if halt.stop.reference == stop_reference][0]

mercurial