first commit
This commit is contained in:
parent
0a1a5fc7c3
commit
bd12b740d1
|
|
@ -0,0 +1,91 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
import requests
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import time
|
||||||
|
import datetime
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
def searchStop(name):
|
||||||
|
|
||||||
|
url = "https://webapi.vvo-online.de/tr/pointfinder"
|
||||||
|
myobj = {"query": name, "stopsOnly": True, "regionalOnly": True}
|
||||||
|
|
||||||
|
x = requests.post(url, json=myobj)
|
||||||
|
x = x.json()
|
||||||
|
points = x["Points"]
|
||||||
|
stops = []
|
||||||
|
for Point in x["Points"]:
|
||||||
|
stops.append([Point.split(sep="|")[0], Point.split(sep="|")[3]])
|
||||||
|
|
||||||
|
return stops
|
||||||
|
|
||||||
|
|
||||||
|
def selectStop(stops):
|
||||||
|
print("Your query matches the following stops:\n")
|
||||||
|
for i, stop in enumerate(stops):
|
||||||
|
print(f"({i}) {stop[1]}")
|
||||||
|
selection = int(input("\nPlease select... "))
|
||||||
|
stopId = stops[selection][0]
|
||||||
|
stopName = stops[selection][1]
|
||||||
|
return stopId, stopName
|
||||||
|
|
||||||
|
|
||||||
|
def getMaxLength(elem, array):
|
||||||
|
return max(map(lambda f: len(f[elem]), array))
|
||||||
|
|
||||||
|
def getDepartures(stopId):
|
||||||
|
url = "https://webapi.vvo-online.de/dm"
|
||||||
|
myobj = {"stopid": stopId}
|
||||||
|
|
||||||
|
x = requests.post(url, json=myobj)
|
||||||
|
x = x.json()
|
||||||
|
for Departure in x["Departures"]:
|
||||||
|
MotType = Departure["Mot"]
|
||||||
|
LineName = Departure["LineName"]
|
||||||
|
Direction = Departure["Direction"]
|
||||||
|
ScheduledTime = datetime.datetime.fromtimestamp(
|
||||||
|
int(re.match(r"/Date[(](\d*)", Departure["ScheduledTime"]).group(1)) / 1000
|
||||||
|
)
|
||||||
|
if "RealTime" in Departure:
|
||||||
|
RealTime = datetime.datetime.fromtimestamp(
|
||||||
|
int(re.match(r"/Date[(](\d*)", Departure["RealTime"]).group(1)) / 1000
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
RealTime = None
|
||||||
|
if "State" in Departure and Departure["State"] == "Delayed":
|
||||||
|
delay = RealTime - ScheduledTime
|
||||||
|
else:
|
||||||
|
delay = ""
|
||||||
|
print(f"{MotType:>{getMaxLength("Mot",x["Departures"])}s} "
|
||||||
|
f"{LineName:>{getMaxLength("LineName",x['Departures'])}s} "
|
||||||
|
f"{Direction:{getMaxLength("Direction",x["Departures"])}s} "
|
||||||
|
f"{ScheduledTime} "
|
||||||
|
f"{RealTime} "
|
||||||
|
f"{delay} "
|
||||||
|
)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
prog="VVO EFA Haltestellenauskunft", description="Miau!", epilog="=^.^="
|
||||||
|
)
|
||||||
|
|
||||||
|
parser.add_argument("stopQuery") # positional argument
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
stop = searchStop(args.stopQuery)
|
||||||
|
|
||||||
|
if len(stop) > 1:
|
||||||
|
stopId, stopName = selectStop(stop)
|
||||||
|
else:
|
||||||
|
stopId = stop[0][0]
|
||||||
|
getDepartures(stopId)
|
||||||
|
|
||||||
|
sys.exit()
|
||||||
Loading…
Reference in New Issue