diff --git a/backend.py b/backend.py index 6ace7d0..fd44e0c 100644 --- a/backend.py +++ b/backend.py @@ -10,7 +10,7 @@ The application will provide routing information and station departures/arrivals import requests import json import re -from datetime import datetime +from datetime import date, datetime from prompt_toolkit import Application from prompt_toolkit.completion import WordCompleter @@ -44,6 +44,13 @@ class HafasClient: headers=self.headers) return json.loads(res.text) + def journeyRequest(self, origin, destination, via=None): + time = datetime.now() + res = self.session.post(self.baseUrl, + data=json.dumps({"svcReqL": [{"req": {"arrLocL": [{"lid": f"A=1@L={destination}@"}], "viaLocL": via or [], "depLocL": [{"lid": f"A=1@L={origin}@"}], "outDate": time.strftime("%Y%m%d"), "outTime": time.strftime("%H%M%S"), "jnyFltrL": [{"type": "PROD", "mode": "INC", "value": "4087"}], "minChgTime": 0, "maxChg": -1, "numF": 1}, "meth": "TripSearch"}], "client": self.clientInfo, "ver": self.version, "lang": self.language, "auth": self.auth}), + headers=self.headers) + return json.loads(res.text) + def getStationNames(self, stationString): @@ -122,6 +129,12 @@ class HafasClient: #arrivalsRaw = self.arrDepRequest(station[0][1], arrdep="ARR", count=1) #__import__('pprint').pprint(arrivalsRaw) + def journeyTest(self): + origin = self.getStationNames(input("Origin: "))[0][1] + destination = self.getStationNames(input("Destination: "))[0][1] + journeys = self.journeyRequest(origin, destination) + __import__('pprint').pprint(journeys) + # streq = self.stationRequest(station)["svcResL"][0]["res"]["match"]["locL"] # @@ -140,4 +153,5 @@ class HafasClient: if __name__ == '__main__': client = HafasClient() # client.runTests() - client.monitorTest() + # client.monitorTest() + client.journeyTest()