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 requests import get
from datetime import datetime, timedelta
from typing import Union
from requests import get
from xmltodict import parse as xmlparse
try:
@@ -8,33 +9,35 @@ try:
except ImportError:
from typing_extensions import Literal
# 2.24. Departure Board (departureBoard)
def board_departure(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["DEP", "DEP_EQUIVS", "DEP_MAST", "DEP_STATION"] = "DEP"
) -> dict:
def board_departure(
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["DEP", "DEP_EQUIVS", "DEP_MAST", "DEP_STATION"] = "DEP",
) -> dict:
"""The separture board can be retrieved by a call to the departureBoard service. This method will return the
next departures (or less if not existing) from a given point in time within a duration covered time span. The
default duration size is 60 minutes.
default duration size is 60 minutes.
Note: The result list always contains all departures running the the last minute found even if the requested
maximum was overrun.
maximum was overrun.
Read more about this in section 2.24. "Departure Board (departureBoard)" of HAFAS ReST Documentation.
Read more about this in section 2.24. "Departure Board (departureBoard)" 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).
@@ -57,14 +60,10 @@ def board_departure(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":
@@ -75,16 +74,12 @@ def board_departure(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()
@@ -94,7 +89,4 @@ def board_departure(accessId: str,
output = get("https://www.rmv.de/hapi/departureBoard", params=payload, headers=headers)
if json:
return output.json()
else:
return xmlparse(output.content)
return output.json() if json else xmlparse(output.content)