From 5068c7a302da03a238bda52352070d895691910b Mon Sep 17 00:00:00 2001 From: mia Date: Wed, 6 May 2026 11:35:53 +0200 Subject: [PATCH] Basic Station Search --- flake.lock | 27 +++++++++++++++++++++++++++ flake.nix | 23 +++++++++++++++++++++++ main.py | 27 +++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..e9646fe --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1778003029, + "narHash": "sha256-q/nkKLDtHIyLjZpKhWk3cSK5IYsFqtMd6UtXF3ddjgA=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "0c88e1f2bdb93d5999019e99cb0e61e1fe2af4c5", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-25.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..68ab227 --- /dev/null +++ b/flake.nix @@ -0,0 +1,23 @@ +{ + description = "Python env for HaFaS-Terminal-App"; + + inputs.nixpkgs.url = github:nixos/nixpkgs/nixos-25.11; + + outputs = { self, nixpkgs, ... }: let + system = "x86_64-linux"; + pkgs = import nixpkgs { inherit system; }; + nixPackages = with pkgs; with python313Packages; [ + requests + prompt-toolkit + ]; + in { + devShells."${system}".default = pkgs.mkShell { + buildInputs = with pkgs; [ + python313 + ] ++ nixPackages; + shellHook = '' + exec zsh || exec bash || true + ''; + }; + }; +} diff --git a/main.py b/main.py index bc3187c..369ffb2 100644 --- a/main.py +++ b/main.py @@ -9,5 +9,32 @@ 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)