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,5 +1,6 @@
from requests import get
from typing import Union
from requests import get
from xmltodict import parse as xmlparse
try:
@@ -7,33 +8,37 @@ try:
except ImportError:
from typing_extensions import Literal
# 2.3. Location Search by Name (location.name)
def stop_by_name(accessId: str,
inputString: str,
lang: Literal["de", "da", "en", "es", "fr", "hu", "it", "nl", "no", "pl", "sv", "tr"] = "en",
json: bool = True,
maxNo: int = 10,
stopType: Literal["A", "ALL", "AP", "P", "S", "SA", "SP"] = "ALL",
locationSelectionMode: Union[Literal["SLCT_N", "SLCT_A"], None] = None,
products: Union[int, None] = None,
coordLat: Union[str, float, None] = None,
coordLong: Union[str, float, None] = None,
radius: Union[int, float] = 1000,
refineId: Union[str, None] = None,
meta: Union[str, None] = None,
stations: Union[str, list, None] = None,
sattributes: Union[str, list, None] = None,
filterMode: Literal["DIST_PERI", "EXCL_PERI", "SLCT_PERI"] = "DIST_PERI"
) -> dict:
def stop_by_name(
accessId: str,
inputString: str,
lang: Literal[
"de", "da", "en", "es", "fr", "hu", "it", "nl", "no", "pl", "sv", "tr"
] = "en",
json: bool = True,
maxNo: int = 10,
stopType: Literal["A", "ALL", "AP", "P", "S", "SA", "SP"] = "ALL",
locationSelectionMode: Union[Literal["SLCT_N", "SLCT_A"], None] = None,
products: Union[int, None] = None,
coordLat: Union[str, float, None] = None,
coordLong: Union[str, float, None] = None,
radius: Union[int, float] = 1000,
refineId: Union[str, None] = None,
meta: Union[str, None] = None,
stations: Union[str, list, None] = None,
sattributes: Union[str, list, None] = None,
filterMode: Literal["DIST_PERI", "EXCL_PERI", "SLCT_PERI"] = "DIST_PERI",
) -> dict:
"""The location.name service can be used to perform a pattern matching of a user input and to retrieve a list
of possible matches in the journey planner database. Possible matches might be stops/stations, points of
interest and addresses.
interest and addresses.
The result is a list of possible matches (locations) where the user might pick one entry to perform a trip
request with this location as origin or destination or to ask for a departure board or arrival board of this
location (stops/stations only).
location (stops/stations only).
Read more about this in section 2.3. "Location Search by Name (location.name)" of HAFAS ReST Documentation.
Read more about this in section 2.3. "Location Search by Name (location.name)" 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).
@@ -55,14 +60,10 @@ def stop_by_name(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) == "inputString":
@@ -80,7 +81,4 @@ def stop_by_name(accessId: str,
output = get("https://www.rmv.de/hapi/location.name", params=payload, headers=headers)
if json:
return output.json()
else:
return xmlparse(output.content)
return output.json() if json else xmlparse(output.content)