Compare commits
No commits in common. "ee6082bf25b5b24af018f208fb09f487cac015d5" and "3d71dbf3f73e6a2a457e37d699c840423e61a157" have entirely different histories.
ee6082bf25
...
3d71dbf3f7
1 changed files with 2 additions and 51 deletions
53
backend.py
53
backend.py
|
|
@ -49,49 +49,9 @@ class HafasClient:
|
||||||
res = self.stationRequest(stationString)
|
res = self.stationRequest(stationString)
|
||||||
return [(station["name"], station["extId"]) for station in res["svcResL"][0]["res"]["match"]["locL"]]
|
return [(station["name"], station["extId"]) for station in res["svcResL"][0]["res"]["match"]["locL"]]
|
||||||
|
|
||||||
def _format_time(self, timeValue):
|
|
||||||
if not timeValue:
|
|
||||||
return None
|
|
||||||
return datetime.strptime(timeValue, "%H%M%S").strftime("%H:%M")
|
|
||||||
|
|
||||||
def getArrDep(self, stationId, arrdep="DEP", count=1):
|
def getArrDep(self, stationId, arrdep="DEP", count=1):
|
||||||
res = self.arrDepRequest(stationId, arrdep, count)
|
res = self.arrDepRequest(stationId, arrdep, count)
|
||||||
departures = []
|
return res["svcResL"][0]["res"]["jnyL"]
|
||||||
time_key = "aTimeS" if arrdep == "ARR" else "dTimeS"
|
|
||||||
time_key_real = "aTimeR" if arrdep == "ARR" else "dTimeR"
|
|
||||||
|
|
||||||
for departure in res["svcResL"][0]["res"]["jnyL"]:
|
|
||||||
prod_list = departure.get("prodL") or []
|
|
||||||
prod_index = departure.get("prodX")
|
|
||||||
if isinstance(prod_index, int) and 0 <= prod_index < len(prod_list):
|
|
||||||
product = prod_list[prod_index]
|
|
||||||
else:
|
|
||||||
product = prod_list[0] if prod_list else {}
|
|
||||||
stop = departure.get("stbStop", {})
|
|
||||||
|
|
||||||
# Raw JSON access pattern:
|
|
||||||
# - Name: departure["dirTxt"]
|
|
||||||
# - Line: departure["prodL"][0]["nameS"] or departure["prodL"][0]["prodCtx"]["line"]
|
|
||||||
# - Departure/arrival time: departure["stbStop"]["dTimeS"] or ["aTimeS"]
|
|
||||||
departures.append({
|
|
||||||
"name": departure.get("dirTxt"),
|
|
||||||
"line": (
|
|
||||||
product.get("nameS")
|
|
||||||
or product.get("number")
|
|
||||||
or product.get("name")
|
|
||||||
or product.get("prodCtx", {}).get("line")
|
|
||||||
or product.get("prodCtx", {}).get("name")
|
|
||||||
or product.get("prodCtx", {}).get("nameS")
|
|
||||||
),
|
|
||||||
"departure_time": self._format_time(stop.get(time_key)),
|
|
||||||
"departure_time_raw": stop.get(time_key),
|
|
||||||
"departure_time_real": self._format_time(stop.get(time_key_real)),
|
|
||||||
"departure_time_real_raw": stop.get(time_key_real),
|
|
||||||
"jid": departure.get("jid"),
|
|
||||||
"raw": departure,
|
|
||||||
})
|
|
||||||
|
|
||||||
return departures
|
|
||||||
|
|
||||||
def getTrip(self, departure):
|
def getTrip(self, departure):
|
||||||
res = self.tripRequest(departure)
|
res = self.tripRequest(departure)
|
||||||
|
|
@ -114,14 +74,6 @@ class HafasClient:
|
||||||
trip = self.getTrip(departures[0]["jid"])
|
trip = self.getTrip(departures[0]["jid"])
|
||||||
__import__('pprint').pprint(trip)
|
__import__('pprint').pprint(trip)
|
||||||
|
|
||||||
def moniterTest(self):
|
|
||||||
stationInput = input("Enter Station Name: ")
|
|
||||||
station = self.getStationNames(stationInput)
|
|
||||||
print(station)
|
|
||||||
# departures = self.getArrDep(station[0][1], arrdep="DEP", count=1)
|
|
||||||
departures = self.arrDepRequest(station[0][1], arrdep="DEP", count=1)
|
|
||||||
print(departures)
|
|
||||||
|
|
||||||
|
|
||||||
# streq = self.stationRequest(station)["svcResL"][0]["res"]["match"]["locL"]
|
# streq = self.stationRequest(station)["svcResL"][0]["res"]["match"]["locL"]
|
||||||
#
|
#
|
||||||
|
|
@ -139,5 +91,4 @@ class HafasClient:
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
client = HafasClient()
|
client = HafasClient()
|
||||||
# client.runTests()
|
client.runTests()
|
||||||
client.moniterTest()
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue