Show intermediate stops, handle too early arrivals
This commit is contained in:
parent
d6f2adb089
commit
7c858272a3
1 changed files with 35 additions and 6 deletions
|
@ -43,11 +43,26 @@ response = json.loads(contents)
|
|||
|
||||
st = ""
|
||||
|
||||
def humantime(t) :
|
||||
return time.strftime("%H:%M", time.localtime(int(t)))
|
||||
|
||||
def delay(s,i) :
|
||||
return (int(s["real"+i]) - int(s["scheduled"+i])) // 60
|
||||
|
||||
def timestring(s,i):
|
||||
if not "real"+i in s :
|
||||
return humantime(s["scheduled"+i])
|
||||
dl = delay(s,i)
|
||||
ht = humantime(s["real"+i])
|
||||
if dl > 0 :
|
||||
return ht + " (+%d)" % dl
|
||||
if dl < 0 :
|
||||
return ht + " (%d)" % dl
|
||||
return ht
|
||||
|
||||
def get_destination(response) :
|
||||
if "toStation" in response :
|
||||
s = response["toStation"]
|
||||
s["humantime"] = time.strftime("%H:%M", time.localtime(int(s["realTime"])))
|
||||
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 :
|
||||
|
@ -61,13 +76,27 @@ 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"]
|
||||
tstr = timestring(s,"Time")
|
||||
st = f'{s["prefname"]} {tstr}'
|
||||
if "train" in response :
|
||||
train = response["train"]
|
||||
tooltip = f'{train["type"]} {train["line"]} ({train["no"]}) to {s["name"]}'
|
||||
if train["line"] is not None :
|
||||
tooltip = f'<b>{train["type"]} {train["line"]} ({train["no"]})</b> to {s["name"]}'
|
||||
else :
|
||||
tooltip = f'<b>{train["type"]} {train["no"]}</b> to {s["name"]}'
|
||||
|
||||
if "intermediateStops" in response :
|
||||
stops = response["intermediateStops"]
|
||||
now = time.time()
|
||||
for stop in stops:
|
||||
if stop["realDeparture"] is not None and int(stop["realDeparture"]) > now :
|
||||
dep = timestring(stop, "Departure")
|
||||
arr = timestring(stop, "Arrival")
|
||||
tooltip = tooltip + f'\n{arr}–{dep} <b>{stop["name"]}</b>'
|
||||
elif int(stop["scheduledDeparture"]) > now :
|
||||
dep = humantime(stop["scheduledDeparture"])
|
||||
arr = humantime(stop["scheduledArrival"])
|
||||
tooltip = tooltip + f'\n<i>{arr}–{dep}</i> <b>{stop["name"]}</b>'
|
||||
|
||||
|
||||
print(json.dumps({"text": st, "tooltip": tooltip, "class": "active", "percentage": ""}))
|
||||
|
|
Loading…
Reference in a new issue