(re)implemented journey planning
This commit is contained in:
parent
dfb2e2716d
commit
9dd6455c92
1 changed files with 16 additions and 2 deletions
18
backend.py
18
backend.py
|
|
@ -10,7 +10,7 @@ The application will provide routing information and station departures/arrivals
|
||||||
import requests
|
import requests
|
||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
from datetime import datetime
|
from datetime import date, datetime
|
||||||
from prompt_toolkit import Application
|
from prompt_toolkit import Application
|
||||||
from prompt_toolkit.completion import WordCompleter
|
from prompt_toolkit.completion import WordCompleter
|
||||||
|
|
||||||
|
|
@ -44,6 +44,13 @@ class HafasClient:
|
||||||
headers=self.headers)
|
headers=self.headers)
|
||||||
return json.loads(res.text)
|
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):
|
def getStationNames(self, stationString):
|
||||||
|
|
@ -122,6 +129,12 @@ class HafasClient:
|
||||||
#arrivalsRaw = self.arrDepRequest(station[0][1], arrdep="ARR", count=1)
|
#arrivalsRaw = self.arrDepRequest(station[0][1], arrdep="ARR", count=1)
|
||||||
#__import__('pprint').pprint(arrivalsRaw)
|
#__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"]
|
# streq = self.stationRequest(station)["svcResL"][0]["res"]["match"]["locL"]
|
||||||
#
|
#
|
||||||
|
|
@ -140,4 +153,5 @@ class HafasClient:
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
client = HafasClient()
|
client = HafasClient()
|
||||||
# client.runTests()
|
# client.runTests()
|
||||||
client.monitorTest()
|
# client.monitorTest()
|
||||||
|
client.journeyTest()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue