catch errors...

This commit is contained in:
Luzia Christiane Tesar 2026-07-28 05:52:35 +02:00
parent e433ca81df
commit 66255627e5
1 changed files with 24 additions and 22 deletions

View File

@ -15,7 +15,7 @@ statusData = None # initialize variables...
tripData = None tripData = None
# Your Travelynx-Api-token goes here # Your Travelynx-Api-token goes here
tlApiToken = "[YOUR TRAVELYNX API TOKEN GOES HERE…]" tlApiToken = ""
# Known SSIDs for some regional train Wifis... # Known SSIDs for some regional train Wifis...
ssid_regio = [ ssid_regio = [
@ -158,7 +158,7 @@ def get_next_tl():
if nextStopArrival >= time.time(): if nextStopArrival >= time.time():
nextStationName = i["name"] nextStationName = i["name"]
uScheduledTime = ["scheduledArrival"] uScheduledTime = i["scheduledArrival"]
uActualTime = i["realArrival"] uActualTime = i["realArrival"]
if uActualTime == None: if uActualTime == None:
arrivalDelay="-" arrivalDelay="-"
@ -174,6 +174,7 @@ def get_next_tl():
break break
else: else:
next next
tripinfo = tripDataTl["toStation"]["name"]
except: except:
tripinfo = tripDataTl["toStation"]["name"] tripinfo = tripDataTl["toStation"]["name"]
return tripinfo return tripinfo
@ -184,33 +185,34 @@ def get_trainInfo_db():
if tripData["trip"]["trainType"] == None: if tripData["trip"]["trainType"] == None:
return "No TrainInfo" return "No TrainInfo"
else: else:
trainType = tripData["trip"]["trainType"] trainType = tripData["trip"]["trainType"] or ""
trainNumber = tripData["trip"]["vzn"] trainNumber = tripData["trip"]["vzn"] or ""
finalStationName = tripData["trip"]["stopInfo"]["finalStationName"] finalStationName = tripData["trip"]["stopInfo"]["finalStationName"] or ""
return trainType + " " + trainNumber return trainType + " " + trainNumber
# Get the Trainnumber and final station of your current travelynx trip # Get the Trainnumber and final station of your current travelynx trip
def get_trainInfo_tl(): def get_trainInfo_tl():
checkin_tl() checkin_tl()
trainType = tripDataTl["train"]["type"] trainType = tripDataTl["train"]["type"] or ""
trainNumber = tripDataTl["train"]["no"] trainNumber = tripDataTl["train"]["no"] or ""
#fromStationName = tripDataTl["fromStation"]["name"] #fromStationName = tripDataTl["fromStation"]["name"]
fromStationDS100=tripDataTl['fromStation']['ds100'] fromStationDS100=tripDataTl['fromStation']['ds100'] or ""
toStationDS100=tripDataTl['toStation']['ds100'] toStationDS100=tripDataTl['toStation']['ds100'] or ""
toStationName = tripDataTl["toStation"]["name"] toStationName = tripDataTl["toStation"]["name"] or ""
toStationTrack = tripDataTl["toStation"]["platform"] toStationTrack = tripDataTl["toStation"]["platform"] or ""
uScheduledTime = tripDataTl["toStation"]["scheduledTime"] uScheduledTime = tripDataTl["toStation"]["scheduledTime"] or ""
uActualTime = tripDataTl["toStation"]["realTime"] uActualTime = tripDataTl["toStation"]["realTime"] or ""
arrivalDelay = "{:+.0f}".format(((uActualTime - uScheduledTime) / 60)) arrivalDelay = "{:+.0f}".format(((uActualTime - uScheduledTime) / 60)) or ""
arrivalTime = datetime.fromtimestamp(uActualTime, tz=timezone).strftime("%H:%M") arrivalTime = datetime.fromtimestamp(uActualTime, tz=timezone).strftime("%H:%M") or ""
nextStop=get_next_tl()
return ( return (
trainType trainType
+ " " + " "
+ trainNumber + trainNumber
+ " | " + " | "
+ fromStationDS100 + nextStop
+ "" + ""
+ toStationDS100 + (toStationDS100 or toStationName)
+ " " + " "
+ arrivalTime + arrivalTime
+ " (" + " ("
@ -220,6 +222,7 @@ def get_trainInfo_tl():
) )
def checkin_tl(): def checkin_tl():
if tripDataTl["checkedIn"] == False: if tripDataTl["checkedIn"] == False:
sys.exit() sys.exit()
@ -244,11 +247,11 @@ def main():
) )
else: else:
get_api_tl() get_api_tl()
print(re.sub(r"\s+", " ", get_trainInfo_tl() + " | NEXT: " + get_next_tl())) print(re.sub(r"\s+", " ", get_trainInfo_tl()))
if get_ssid() in ssid_regio: if get_ssid() in ssid_regio:
get_api_tl() get_api_tl()
print(re.sub(r"\s+", " ", get_trainInfo_tl() + " | NEXT: " + get_next_tl())) print(re.sub(r"\s+", " ", get_trainInfo_tl()))
if get_ssid() == "CDWiFi": if get_ssid() == "CDWiFi":
get_api_tl() get_api_tl()
@ -261,8 +264,7 @@ def main():
+ " | " + " | "
+ "SPEED: " + "SPEED: "
+ get_speed_cd() + get_speed_cd()
+ " km/h | NEXT: " + " km/h"
+ get_next_tl(),
) )
) )