Small refactor and isort+black formatting
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from requests import get
|
||||
from typing import Union
|
||||
|
||||
from requests import get
|
||||
from xmltodict import parse as xmlparse
|
||||
|
||||
try:
|
||||
@@ -7,25 +8,29 @@ try:
|
||||
except ImportError:
|
||||
from typing_extensions import Literal
|
||||
|
||||
# 2.4. Location Search by Coordinate (location.nearbystops)
|
||||
def stop_by_coords(accessId: str,
|
||||
originCoordLat: Union[str, float],
|
||||
originCoordLong: Union[str, float],
|
||||
lang: Literal["de", "da", "en", "es", "fr", "hu", "it", "nl", "no", "pl", "sv", "tr"] = "en",
|
||||
json: bool = True,
|
||||
radius: Union[int, float] = 1000,
|
||||
maxNo: int = 10,
|
||||
stopType: Literal["S", "P", "SP", "SE", "SPE"] = "S",
|
||||
locationSelectionMode: Union[Literal["SLCT_N", "SLCT_A"], None] = None,
|
||||
products: Union[int, None] = None,
|
||||
meta: Union[str, None] = None,
|
||||
sattributes: Union[str, list, None] = None,
|
||||
sinfotexts: Union[str, list, None] = None
|
||||
) -> dict:
|
||||
"""The location.nearbystops service returns a list of stops around a given center coordinate (within a
|
||||
radius of 1000m). The returned results are ordered by their distance to the center coordinate.
|
||||
|
||||
Read more about this in section 2.4. "Location Search by Coordinate (location.nearbystops)" of HAFAS ReST Documentation.
|
||||
# 2.4. Location Search by Coordinate (location.nearbystops)
|
||||
def stop_by_coords(
|
||||
accessId: str,
|
||||
originCoordLat: Union[str, float],
|
||||
originCoordLong: Union[str, float],
|
||||
lang: Literal[
|
||||
"de", "da", "en", "es", "fr", "hu", "it", "nl", "no", "pl", "sv", "tr"
|
||||
] = "en",
|
||||
json: bool = True,
|
||||
radius: Union[int, float] = 1000,
|
||||
maxNo: int = 10,
|
||||
stopType: Literal["S", "P", "SP", "SE", "SPE"] = "S",
|
||||
locationSelectionMode: Union[Literal["SLCT_N", "SLCT_A"], None] = None,
|
||||
products: Union[int, None] = None,
|
||||
meta: Union[str, None] = None,
|
||||
sattributes: Union[str, list, None] = None,
|
||||
sinfotexts: Union[str, list, None] = None,
|
||||
) -> dict:
|
||||
"""The location.nearbystops service returns a list of stops around a given center coordinate (within a
|
||||
radius of 1000m). The returned results are ordered by their distance to the center coordinate.
|
||||
|
||||
Read more about this in section 2.4. "Location Search by Coordinate (location.nearbystops)" 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).
|
||||
@@ -44,14 +49,10 @@ def stop_by_coords(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) == "stopType":
|
||||
@@ -64,9 +65,8 @@ def stop_by_coords(accessId: str,
|
||||
if val != None:
|
||||
payload[str(var)] = val
|
||||
|
||||
output = get("https://www.rmv.de/hapi/location.nearbystops", params=payload, headers=headers)
|
||||
output = get(
|
||||
"https://www.rmv.de/hapi/location.nearbystops", params=payload, headers=headers
|
||||
)
|
||||
|
||||
if json:
|
||||
return output.json()
|
||||
else:
|
||||
return xmlparse(output.content)
|
||||
return output.json() if json else xmlparse(output.content)
|
||||
|
Reference in New Issue
Block a user