Small refactor and isort+black formatting
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from requests import get
|
||||
from datetime import datetime, timedelta
|
||||
from typing import Union
|
||||
|
||||
from requests import get
|
||||
from xmltodict import parse as xmlparse
|
||||
|
||||
try:
|
||||
@@ -8,32 +9,34 @@ try:
|
||||
except ImportError:
|
||||
from typing_extensions import Literal
|
||||
|
||||
|
||||
# 2.25. Arrival Board (arrivalBoard)
|
||||
def board_arrival(accessId: str,
|
||||
json: bool = True,
|
||||
id: Union[str, None] = None,
|
||||
extId: Union[str, None] = None,
|
||||
direction: Union[str, None] = None,
|
||||
date: Union[str, datetime, None] = None,
|
||||
time: Union[str, datetime, None] = None,
|
||||
duration: Union[int, timedelta] = 60,
|
||||
maxJourneys: int = -1,
|
||||
products: Union[int, None] = None,
|
||||
operators: Union[str, list, None] = None,
|
||||
lines: Union[str, list, None] = None,
|
||||
filterEquiv: bool = True,
|
||||
attributes: Union[str, list, None] = None,
|
||||
platforms: Union[str, list, None] = None,
|
||||
passlist: bool = False,
|
||||
boardType: Literal["ARR", "ARR_EQUIVS", "ARR_MAST", "ARR_STATION"] = "ARR"
|
||||
) -> dict:
|
||||
def board_arrival(
|
||||
accessId: str,
|
||||
json: bool = True,
|
||||
id: Union[str, None] = None,
|
||||
extId: Union[str, None] = None,
|
||||
direction: Union[str, None] = None,
|
||||
date: Union[str, datetime, None] = None,
|
||||
time: Union[str, datetime, None] = None,
|
||||
duration: Union[int, timedelta] = 60,
|
||||
maxJourneys: int = -1,
|
||||
products: Union[int, None] = None,
|
||||
operators: Union[str, list, None] = None,
|
||||
lines: Union[str, list, None] = None,
|
||||
filterEquiv: bool = True,
|
||||
attributes: Union[str, list, None] = None,
|
||||
platforms: Union[str, list, None] = None,
|
||||
passlist: bool = False,
|
||||
boardType: Literal["ARR", "ARR_EQUIVS", "ARR_MAST", "ARR_STATION"] = "ARR",
|
||||
) -> dict:
|
||||
"""The arrival board can be retrieved by a call to the arrivalBoard service. This method will return the next
|
||||
arrivals from a given point in time within a duration covered time span. The default duration size is 60 minutes.
|
||||
arrivals from a given point in time within a duration covered time span. The default duration size is 60 minutes.
|
||||
|
||||
Note: The result list always contains all arrivals running the the last minute found even if the requested
|
||||
maximum was overrun.
|
||||
maximum was overrun.
|
||||
|
||||
Read more about this in section 2.25. "Arrival Board (arrivalBoard)" of HAFAS ReST Documentation.
|
||||
Read more about this in section 2.25. "Arrival Board (arrivalBoard)" 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).
|
||||
@@ -56,14 +59,10 @@ def board_arrival(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":
|
||||
@@ -74,16 +73,12 @@ def board_arrival(accessId: str,
|
||||
payload[str(var)] = val
|
||||
elif str(var) == "time":
|
||||
if val != None:
|
||||
if isinstance(val, datetime):
|
||||
payload[str(var)] = val.strftime("%H:%M")
|
||||
else:
|
||||
payload[str(var)] = val
|
||||
payload[str(var)] = (
|
||||
val.strftime("%H:%M") if isinstance(val, datetime) else val
|
||||
)
|
||||
elif str(var) == "duration":
|
||||
if val != None:
|
||||
if isinstance(val, timedelta):
|
||||
payload[str(var)] = val.minutes # type: ignore
|
||||
else:
|
||||
payload[str(var)] = val
|
||||
payload[str(var)] = val.minutes if isinstance(val, timedelta) else val
|
||||
elif str(var) == "boardType":
|
||||
if val != None:
|
||||
payload["type"] = val.upper()
|
||||
@@ -93,7 +88,4 @@ def board_arrival(accessId: str,
|
||||
|
||||
output = get("https://www.rmv.de/hapi/arrivalBoard", 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