Small refactor and isort+black formatting
Some checks reported warnings
Tests / test (3.11) (push) Has been cancelled
Tests / test (3.8) (push) Has been cancelled
Tests / test (3.9) (push) Has been cancelled
Tests / test (3.10) (push) Has been cancelled

This commit is contained in:
2023-11-24 11:21:02 +01:00
parent fa4f7b83ec
commit f31fa65d78
45 changed files with 1035 additions and 923 deletions

View File

@@ -1,6 +1,7 @@
from datetime import datetime
from requests import get
from typing import Union
from requests import get
from xmltodict import parse as xmlparse
try:
@@ -8,43 +9,44 @@ try:
except ImportError:
from typing_extensions import Literal
# 2.17. Reconstruction (recon)
def trip_recon(accessId: str,
ctx: str,
json: bool = True,
poly: bool = False,
polyEnc: Literal["DLT", "GPA", "N"] = "N",
date: Union[str, datetime, None] = None,
useCombinedComparison: Union[bool, None] = None,
acceptGaps: Union[bool, None] = None,
allowDummySections: Union[bool, None] = None,
flagAllNonReachable: Union[bool, None] = None,
matchCatStrict: Union[bool, None] = None,
matchIdNonBlank: Union[bool, None] = None,
matchIdStrict: Union[bool, None] = None,
matchNumStrict: Union[bool, None] = None,
matchRtType: Union[bool, None] = None,
enableRtFullSearch: Union[bool, None] = None,
enableReplacements: Union[bool, None] = None,
arrL: Union[int, None] = None,
arrU: Union[int, None] = None,
depL: Union[int, None] = None,
depU: Union[int, None] = None,
passlist: bool = False,
showPassingPoints: bool = False,
rtMode: Union[Literal["FULL", "INFOS", "OFF", "REALTIME", "SERVER_DEFAULT"], None] = None,
eco: bool = False,
ecoCmp: bool = False,
ecoParams: Union[str, None] = None,
tariff: Union[bool, None] = None,
trafficMessages: Union[bool, None] = None,
travellerProfileData: Union[str, None] = None
) -> dict:
def trip_recon(
accessId: str,
ctx: str,
json: bool = True,
poly: bool = False,
polyEnc: Literal["DLT", "GPA", "N"] = "N",
date: Union[str, datetime, None] = None,
useCombinedComparison: Union[bool, None] = None,
acceptGaps: Union[bool, None] = None,
allowDummySections: Union[bool, None] = None,
flagAllNonReachable: Union[bool, None] = None,
matchCatStrict: Union[bool, None] = None,
matchIdNonBlank: Union[bool, None] = None,
matchIdStrict: Union[bool, None] = None,
matchNumStrict: Union[bool, None] = None,
matchRtType: Union[bool, None] = None,
enableRtFullSearch: Union[bool, None] = None,
enableReplacements: Union[bool, None] = None,
arrL: Union[int, None] = None,
arrU: Union[int, None] = None,
depL: Union[int, None] = None,
depU: Union[int, None] = None,
passlist: bool = False,
showPassingPoints: bool = False,
rtMode: Union[Literal["FULL", "INFOS", "OFF", "REALTIME", "SERVER_DEFAULT"], None] = None,
eco: bool = False,
ecoCmp: bool = False,
ecoParams: Union[str, None] = None,
tariff: Union[bool, None] = None,
trafficMessages: Union[bool, None] = None,
travellerProfileData: Union[str, None] = None,
) -> dict:
"""Reconstructing a trip can be achieved using the reconstruction context provided by any trip result in the
ctxRecon attribute of Trip element. The result will be a true copy of the original trip search result given
that the underlying data did not change.
that the underlying data did not change.
Read more about this in section 2.17. "Reconstruction (recon)" of HAFAS ReST Documentation.
Read more about this in section 2.17. "Reconstruction (recon)" of HAFAS ReST Documentation.
### Args:
* accessId (str): Access ID for identifying the requesting client. Get your key on [RMV website](https://opendata.rmv.de/site/start.html).
@@ -80,14 +82,10 @@ def trip_recon(accessId: str,
### Returns:
* dict: Output from RMV. Dict will contain "errorCode" and "errorText" if exception occurs.
"""
if json:
headers = {"Accept": "application/json"}
else:
headers = {"Accept": "application/xml"}
"""
payload = {}
headers = {"Accept": "application/json"} if json else {"Accept": "application/xml"}
for var, val in locals().items():
if str(var) == "date":
@@ -102,7 +100,4 @@ def trip_recon(accessId: str,
output = get("https://www.rmv.de/hapi/recon", params=payload, headers=headers)
if json:
return output.json()
else:
return xmlparse(output.content)
return output.json() if json else xmlparse(output.content)