-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbvg.py
executable file
·34 lines (29 loc) · 1.04 KB
/
bvg.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python3
import time
import serial
from bvggrabber.api.actualdeparture import ActualDepartureQueryApi
from bvggrabber.api.scheduleddeparture import ScheduledDepartureQueryApi, Vehicle
PORT = '/dev/serial/by-id/usb-Arduino__www.arduino.cc__0043_952323438333517040A1-if00'
def departures():
query = ActualDepartureQueryApi('Herzbergstr./Siegfriedstr. (Berlin)')
res = query.call()
return [ '{:%H:%M} {} {}'.format(departure.when, departure.line.split()[-1], departure.end)
for start, departures in res.departures
for departure in sorted(departures, key=lambda dep:dep.when) ]
ser = serial.Serial(PORT, 115200, timeout=0)
time.sleep(3)
while True:
line = ' | '.join(departures())
for a, b in (
('ä', 'ae'),
('Ä', 'AE'),
('ö', 'oe'),
('Ö', 'OE'),
('ü', 'ue'),
('Ü', 'UE'),
('ß', 'ss'),
):
line = line.replace(a, b)
print(line)
ser.write((line+'\r').encode('utf8'))
time.sleep(300)