Add option to keep showing last checkin, option to switch Ds100 on and off

This commit is contained in:
Antonia 2024-02-08 12:17:08 +01:00
parent 477f86e006
commit 7a7285106b
2 changed files with 33 additions and 15 deletions

View file

@ -2,8 +2,8 @@
This script adds a very simple [travelynx](https://travelynx.de) This script adds a very simple [travelynx](https://travelynx.de)
integration into [waybar](https://github.com/Alexays/Waybar), showing integration into [waybar](https://github.com/Alexays/Waybar), showing
DS100 (or if it doesn't exist, the name) of the station the user is the name of the station the user is traveling to as well as the
checked into as well as the currently estimated arrival time. currently estimated arrival time.
## Usage ## Usage

View file

@ -27,27 +27,45 @@ import sys
import json import json
import urllib.request import urllib.request
import time import time
import argparse
token = sys.argv[1] parser = argparse.ArgumentParser(description='Travelynx Integration for waybar')
parser.add_argument("token", help="travelynx status API token")
parser.add_argument("-l", "--last-checkin", metavar="MINUTES", help="keep showing last checkin for a given amount of minutes, 0 for indefinitely", type=int,)
parser.add_argument("-d", "--ds-100", action="store_true", help="Prefer DS100 codes for stations", default=False)
args = parser.parse_args()
token = args.token
contents = urllib.request.urlopen("https://travelynx.de/api/v1/status/"+token).read() contents = urllib.request.urlopen("https://travelynx.de/api/v1/status/"+token).read()
response = json.loads(contents) response = json.loads(contents)
#print(response)
s = "" st = ""
if response["checkedIn"] : def get_destination(response) :
if "toStation" in response : if "toStation" in response :
s = response["toStation"] s = response["toStation"]
if "ds100" in s and s["ds100"] : s["humantime"] = time.strftime("%H:%M", time.localtime(int(s["realTime"])))
name = s["ds100"] s["delay"] = (int(s["realTime"]) - int(s["scheduledTime"])) // 60
if "ds100" in s and s["ds100"] and args.ds_100 :
s["prefname"] = s["ds100"]
else : else :
name = s["name"] s["prefname"] = s["name"]
arrtime = time.strftime("%H:%M", time.localtime(int(s["realTime"]))) return s
delay = (int(s["realTime"]) - int(s["scheduledTime"])) // 60 else:
s = f'{name} {arrtime}' return None
if delay > 0 :
s = s + " (+%d)" % delay
print(json.dumps({"text": s, "tooltip": "", "class": "active", "percentage": ""})) checked_in = response["checkedIn"]
if checked_in or args.last_checkin is not None :
s = get_destination(response)
elapsed = int(time.time()) - int(s["realTime"])
if checked_in or args.last_checkin == 0 or args.last_checkin * 60 > elapsed :
st = f'{s["prefname"]} {s["humantime"]}'
if s["delay"] > 0 :
st = st + " (+%d)" % s["delay"]
print(json.dumps({"text": st, "tooltip": "", "class": "active", "percentage": ""}))