real_time_stop_display.py

Fri, 07 Sep 2018 00:23:42 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Fri, 07 Sep 2018 00:23:42 +0300
changeset 109
88a5110b66ba
parent 72
65408ed066b3
permissions
-rw-r--r--

added some features

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