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