From bd12b740d113a87d2e457bc3c72fc1f58f822c4b Mon Sep 17 00:00:00 2001 From: chrissy Date: Mon, 6 Apr 2026 19:02:37 +0200 Subject: [PATCH] first commit --- efa.py | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100755 efa.py diff --git a/efa.py b/efa.py new file mode 100755 index 0000000..38a359c --- /dev/null +++ b/efa.py @@ -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()