Show actual destination in case of incomplete route (e.g. for some international trains)

This commit is contained in:
Julian Metzler 2024-04-01 11:44:57 +02:00
parent 9d6efef004
commit 37fa7ed358
1 changed files with 12 additions and 2 deletions

14
run.py
View File

@ -156,8 +156,18 @@ def update_display(display, dbi):
text = text.rstrip("Hbf").strip()
display.destination.set(text)
else:
dest = filter_route(train['route'])[-1]['name']
dest = re.sub(r"\(.*\)$", "", dest).strip()
# Check if the last stop matches the destination.
# For some international trains, the route stops at the border,
# but the destination is correct.
# This is different from cancelled stops, which do show up in the route,
# but with the "isCancelled" flag set."
if train['route'][-1] != train['destination']:
# Incomplete route, show actual destination
dest = train['destination']
else:
# Normal route
dest = filter_route(train['route'])[-1]['name']
dest = re.sub(r"\(.*\)$", "", dest).strip() # Filter out suffixes in parentheses
text = DESTINATION_MAP.get(dest, dest).replace("ß", "ss")
if train_type == "S":
text = "".join(train['train'].split()) + " " + text