Created
January 6, 2025 10:32
-
-
Save CatoLynx/b16eba5a83b33e8d9966eb7025238153 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from deutschebahn import DBInfoscreen | |
from pyfis.aegmis import ECSLCDisplay | |
from local_settings import * | |
def get_info_long(train): | |
messages = [] | |
if train.get('isCancelled'): | |
messages.append("fällt aus") | |
else: | |
if train.get('platform') != train.get('scheduledPlatform'): | |
messages.append("heute von Gleis {}".format(train['platform'])) | |
delay = DBInfoscreen.round_delay(train.get('delayDeparture', 0) or train.get('delayArrival', 0)) | |
if delay: | |
if delay > 0: | |
messages.append("etwa {} Minuten später".format(delay)) | |
else: | |
messages.append("unbestimmt verspätet") | |
for msg in train['messages']['qos']: | |
messages.append(msg['text']) | |
if messages: | |
return " +++ ".join(messages) + " +++ " | |
else: | |
return "" | |
def display_train(d, page, train): | |
info = get_info_long(train) | |
d.define_normal_page(page) | |
d.select_page(page) | |
# Platform number front | |
d.change_sector(0, 382, 0, 92, 64, 'text', font=8, lines=1) | |
d.select_sector(0) | |
d.chr_out_text(0, train['platform'] or "", align='right', attribute='normal') | |
# Platform number rear | |
d.change_sector(1, 4, 64, 92, 64, 'text', font=8, lines=1) | |
d.select_sector(1) | |
d.chr_out_text(0, train['platform'] or "", align='left', attribute='normal') | |
# Departure time front | |
d.change_sector(2, 4, 2, 92, 24, 'text', font=6, lines=1) | |
d.select_sector(2) | |
d.chr_out_text(0, train['scheduledDeparture'] or train['scheduledArrival'], align='left', attribute='normal') | |
# Departure time rear | |
d.change_sector(3, 384, 66, 92, 24, 'text', font=6, lines=1) | |
d.select_sector(3) | |
d.chr_out_text(0, train['scheduledDeparture'] or train['scheduledArrival'], align='right', attribute='normal') | |
# Train number front | |
d.change_sector(4, 4, 24, 92, 16, 'text', font=1, lines=1) | |
d.select_sector(4) | |
d.chr_out_text(0, train['train'], align='left', attribute='normal') | |
# Train number rear | |
d.change_sector(5, 384, 88, 92, 16, 'text', font=1, lines=1) | |
d.select_sector(5) | |
d.chr_out_text(0, train['train'], align='right', attribute='normal') | |
# Destination front | |
d.change_sector(6, 97, 36, 288, 28, 'text', font=7, lines=1) | |
d.select_sector(6) | |
d.chr_out_text(0, train['destination'] if train['scheduledDeparture'] else "von " + train['route'][0]['name'], align='left', attribute='normal') | |
# Destination rear | |
d.change_sector(7, 97, 100, 288, 28, 'text', font=7, lines=1) | |
d.select_sector(7) | |
d.chr_out_text(0, train['destination'] if train['scheduledDeparture'] else "von " + train['route'][0]['name'], align='left', attribute='normal') | |
# Via front | |
d.change_sector(8, 96, 18, 288, 16, 'text', font=1, lines=1) | |
d.select_sector(8) | |
d.chr_out_text(0, "\xb4".join(train['via']), align='left', attribute='normal') | |
# Via rear | |
d.change_sector(9, 96, 82, 288, 16, 'text', font=1, lines=1) | |
d.select_sector(9) | |
d.chr_out_text(0, "\xb4".join(train['via']), align='left', attribute='normal') | |
if info: | |
# Info front | |
d.change_sector(10, 96, 0, 288, 16, 'text', font=2, lines=1) | |
d.select_sector(10) | |
d.chr_out_text(0, info, align='flow', attribute='invers') | |
# Info rear | |
d.change_sector(11, 96, 64, 288, 16, 'text', font=2, lines=1) | |
d.select_sector(11) | |
d.chr_out_text(0, info, align='flow', attribute='invers') | |
d.show_page(page) | |
def main(): | |
display = ECSLCDisplay(DISPLAY_IP, double_sided=True, debug=True) | |
dbi = DBInfoscreen(DBI_HOST) | |
trains = dbi.calc_real_times(dbi.get_trains(DBI_STATION)) | |
if not trains: | |
print("nope") | |
display.display_text(1, "Kein Zugverkehr", 7) | |
else: | |
train = trains[0] | |
display_train(display, 1, train) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment