diff --git a/backend.py b/backend.py deleted file mode 100644 index 8bb755d..0000000 --- a/backend.py +++ /dev/null @@ -1,50 +0,0 @@ -""" -haTerm - v0.1 -(c) Kieler Mia, Chiara Wohlwend, Sophia Schmidhofer - -haTerm is a Terminal Based hafas client, using the ivb endpoint. -Prompt_toolkit (https://github.com/prompt-toolkit/python-prompt-toolkit) will be used to render a terminal user interface (TUI). -The application will provide routing information and station departures/arrivals. -""" - -import requests -import json -from datetime import datetime -from prompt_toolkit import Application -from prompt_toolkit.completion import WordCompleter - -def stationRequest(station): - res = session.post("https://fahrplan.ivb.at/bin/mgate.exe", - data=json.dumps({"svcReqL": [{"req": {"input": {"field": "S", "loc": {"name": station, "type": "S"}}}, "meth": "LocMatch"}], "client": {"id": "VAO", "name": "webapp", "type": "WEB"}, "ver": "1.32", "lang": "de", "auth": {"type": "AID", "aid": "wf7mcf9bv3nv8g5f"}}), - headers={'User-Agent': "IOS",'Content-Type': 'application/json'}) - return json.loads(res.text) - -def departuresRequest(station, departures=1): - time = datetime.now() - print(time.strftime("%Y%m%d")) - res = session.post("https://fahrplan.ivb.at/bin/mgate.exe", - data=json.dumps({"svcReqL": [{"req": {"type": "DEP", "stbLoc": {"lid": f"A=1@L={station}@"}, "dirLoc": None, "maxJny": departures, "date": time.strftime("%Y%m%d"), "time": time.strftime("%H%M%S"), "dur": -1, "jnyFltrL": [{"type": "PROD", "mode": "INC", "value": "4087"}]}, "meth": "StationBoard"}], "client": {"id": "VAO", "name": "webapp", "type": "WEB"}, "ver": "1.32", "lang": "de", "auth": {"type": "AID", "aid": "wf7mcf9bv3nv8g5f"}}), - headers={'User-Agent': "IOS",'Content-Type': 'application/json'}) - return json.loads(res.text) - -def tripRequest(departure): - res = session.post("https://fahrplan.ivb.at/bin/mgate.exe", - data = json.dumps({"svcReqL": [{"req": {"jid": departure}, "meth": "JourneyDetails"}], "client": {"id": "VAO", "name": "webapp", "type": "WEB"}, "ver": "1.32", "lang": "de", "auth": {"type": "AID", "aid": "wf7mcf9bv3nv8g5f"}}), - headers={'User-Agent': "IOS",'Content-Type': 'application/json'}) - return json.loads(res.text) - -if __name__ == '__main__': - session = requests.session() - station = input("Enter Station Name: ") - streq = stationRequest(station)["svcResL"][0]["res"]["match"]["locL"] - - selectedStation = streq[0] # should be selected using ptk - __import__('pprint').pprint(selectedStation) - print(selectedStation["lid"]) - dpreq = departuresRequest(selectedStation["lid"], departures=5) - - nextDepartures = dpreq["svcResL"][0]["res"]["jnyL"] - __import__('pprint').pprint(nextDepartures) - for departure in nextDepartures: - print(f"{datetime.strptime(departure["stbStop"]["dTimeS"], "%H%M%S").strftime("%H:%M")} / {datetime.strptime(departure["stbStop"]["dTimeR"], "%H%M%S").strftime("%H:%M")} {departure["dirFlg"]} --> {departure["dirTxt"]}") - print(nextDepartures) diff --git a/main.py b/main.py index b43be72..369ffb2 100644 --- a/main.py +++ b/main.py @@ -6,3 +6,35 @@ haTerm is a Terminal Based hafas client, using the ivb endpoint. Prompt_toolkit (https://github.com/prompt-toolkit/python-prompt-toolkit) will be used to render a terminal user interface (TUI). The application will provide routing information and station departures/arrivals. """ + +import requests +import json +from datetime import datetime +from prompt_toolkit import Application +from prompt_toolkit.completion import WordCompleter + +def stationRequest(station): + res = session.post("https://fahrplan.ivb.at/bin/mgate.exe", + data=json.dumps({"svcReqL": [{"req": {"input": {"field": "S", "loc": {"name": station, "type": "S"}}}, "meth": "LocMatch"}], "client": {"id": "VAO", "name": "webapp", "type": "WEB"}, "ver": "1.32", "lang": "de", "auth": {"type": "AID", "aid": "wf7mcf9bv3nv8g5f"}}), + headers={'User-Agent': "IOS",'Content-Type': 'application/json'}) + return json.loads(res.text) + +def departuresRequest(station): + time = datetime.now() + res = session.post("https://fahrplan.ivb.at/bin/mgate.exe", + data=json.dumps({"svcReqL": [{"req": {"type": "DEP", "stbLoc": {"lid": f"A=1@L={station}@"}, "dirLoc": None, "maxJny": 1, "date": time.strftime("%Y%M%D"), "time": time.strftime("%H%M%S"), "dur": -1, "jnyFltrL": [{"type": "PROD", "mode": "INC", "value": "4087"}]}, "meth": "StationBoard"}], "client": {"id": "VAO", "name": "webapp", "type": "WEB"}, "ver": "1.32", "lang": "de", "auth": {"type": "AID", "aid": "wf7mcf9bv3nv8g5f"}}), + headers={'User-Agent': "IOS",'Content-Type': 'application/json'}) + return json.loads(res.text) + +def tripRequest(departure): + res = session.post("https://fahrplan.ivb.at/bin/mgate.exe", + data = json.dumps({"svcReqL": [{"req": {"jid": departure}, "meth": "JourneyDetails"}], "client": {"id": "VAO", "name": "webapp", "type": "WEB"}, "ver": "1.32", "lang": "de", "auth": {"type": "AID", "aid": "wf7mcf9bv3nv8g5f"}}), + headers={'User-Agent': "IOS",'Content-Type': 'application/json'}) + return json.loads(res.text) + +if __name__ == '__main__': + session = requests.session() + station = input("Enter Station Name: ") + streq = stationRequest(station) + bestFoundStation = streq["svcResL"][0]["res"]["match"]["locL"][0] + print(bestFoundStation) diff --git a/route_planning.py b/route_planning.py deleted file mode 100644 index 4d1ead3..0000000 --- a/route_planning.py +++ /dev/null @@ -1,8 +0,0 @@ -""" -haTerm - v0.1 -(c) Sophia Schmidhofer - -haTerm is a Terminal Based hafas client, using the ivb endpoint. -Prompt_toolkit (https://github.com/prompt-toolkit/python-prompt-toolkit) will be used to render a terminal user interface (TUI). -The application will provide routing information and station departures/arrivals. -""" diff --git a/station_monitor.py b/station_monitor.py deleted file mode 100644 index ffa236c..0000000 --- a/station_monitor.py +++ /dev/null @@ -1,8 +0,0 @@ -""" -haTerm - v0.1 -(c) Chiara Wohlwend - -haTerm is a Terminal Based hafas client, using the ivb endpoint. -Prompt_toolkit (https://github.com/prompt-toolkit/python-prompt-toolkit) will be used to render a terminal user interface (TUI). -The application will provide routing information and station departures/arrivals. -"""