Small refactor and isort+black formatting
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from datetime import datetime
|
||||
from requests import get
|
||||
from typing import List, Union
|
||||
|
||||
from requests import get
|
||||
from xmltodict import parse as xmlparse
|
||||
|
||||
try:
|
||||
@@ -8,125 +9,103 @@ try:
|
||||
except ImportError:
|
||||
from typing_extensions import Literal
|
||||
|
||||
# 2.12. Trip Search (trip)
|
||||
def trip_find(accessId: str,
|
||||
lang: Literal["de", "da", "en", "es", "fr", "hu", "it", "nl", "no", "pl", "sv", "tr"] = "en",
|
||||
json: bool = True,
|
||||
|
||||
originId: Union[str, None] = None,
|
||||
originExtId: Union[str, None] = None,
|
||||
originCoordLat: Union[str, float, None] = None,
|
||||
originCoordLong: Union[str, float, None] = None,
|
||||
originCoordName: Union[str, None] = None,
|
||||
|
||||
destId: Union[str, None] = None,
|
||||
destExtId: Union[str, None] = None,
|
||||
destCoordLat: Union[str, float, None] = None,
|
||||
destCoordLong: Union[str, float, None] = None,
|
||||
destCoordName: Union[str, None] = None,
|
||||
|
||||
via: Union[str, None] = None,
|
||||
viaId: Union[str, None] = None,
|
||||
viaWaitTime: int = 0,
|
||||
|
||||
avoid: Union[str, None] = None,
|
||||
avoidId: Union[str, None] = None,
|
||||
|
||||
viaGis: Union[str, None] = None,
|
||||
|
||||
changeTimePercent: int = 100,
|
||||
minChangeTime: Union[int, None] = None,
|
||||
maxChangeTime: Union[int, None] = None,
|
||||
addChangeTime: Union[int, None] = None,
|
||||
maxChange: Union[int, None] = None,
|
||||
|
||||
date: Union[str, datetime, None] = None,
|
||||
time: Union[str, datetime, None] = None,
|
||||
|
||||
searchForArrival: bool = False,
|
||||
|
||||
numF: Union[int, None] = None,
|
||||
numB: Union[int, None] = None,
|
||||
|
||||
context: Union[str, None] = None,
|
||||
|
||||
poly: bool = False,
|
||||
polyEnc: Literal["DLT", "GPA", "N"] = "N",
|
||||
|
||||
passlist: bool = False,
|
||||
products: Union[int, None] = None,
|
||||
operators: Union[str, list, None] = None,
|
||||
|
||||
attributes: Union[str, list, None] = None,
|
||||
sattributes: Union[str, list, None] = None,
|
||||
fattributes: Union[str, list, None] = None,
|
||||
lines: Union[str, list, None] = None,
|
||||
lineids: Union[str, list, None] = None,
|
||||
|
||||
avoidPaths: Union[List[Literal["SW", "EA", "ES", "RA", "CB"]], None] = None,
|
||||
|
||||
originWalk: Union[str, list, None] = None,
|
||||
originBike: Union[str, list, None] = None,
|
||||
originCar: Union[str, list, None] = None,
|
||||
originTaxi: Union[str, list, None] = None,
|
||||
originPark: Union[str, list, None] = None,
|
||||
originMeta: Union[str, list, None] = None,
|
||||
|
||||
destWalk: Union[str, list, None] = None,
|
||||
destBike: Union[str, list, None] = None,
|
||||
destCar: Union[str, list, None] = None,
|
||||
destTaxi: Union[str, list, None] = None,
|
||||
destPark: Union[str, list, None] = None,
|
||||
destMeta: Union[str, list, None] = None,
|
||||
|
||||
totalWalk: Union[str, list, None] = None,
|
||||
totalBike: Union[str, list, None] = None,
|
||||
totalCar: Union[str, list, None] = None,
|
||||
totalTaxi: Union[str, list, None] = None,
|
||||
totalMeta: Union[str, list, None] = None,
|
||||
|
||||
gisProducts: Union[str, None] = None,
|
||||
|
||||
includeIv: bool = False,
|
||||
ivOnly: bool = False,
|
||||
|
||||
mobilityProfile: Union[str, None] = None,
|
||||
|
||||
bikeCarriage: bool = False,
|
||||
bikeCarriageType: Union[Literal["SINGLEBIKES", "SMALLGROUPS", "LARGEGROUPS"], None] = None,
|
||||
|
||||
sleepingCar: bool = False,
|
||||
couchetteCoach: bool = False,
|
||||
showPassingPoints: bool = False,
|
||||
baim: bool = False,
|
||||
|
||||
eco: bool = False,
|
||||
ecoCmp: bool = False,
|
||||
ecoParams: Union[str, None] = None,
|
||||
|
||||
rtMode: Union[Literal["FULL", "INFOS", "OFF", "REALTIME", "SERVER_DEFAULT"], None] = None,
|
||||
|
||||
unsharp: bool = False,
|
||||
trainFilter: Union[str, None] = None,
|
||||
economic: bool = False,
|
||||
groupFilter: Union[str, None] = None,
|
||||
|
||||
blockingList: Union[str, None] = None,
|
||||
blockedEdges: Union[str, None] = None,
|
||||
|
||||
trainComposition: bool = False,
|
||||
includeEarlier: bool = False,
|
||||
withICTAlternatives: bool = False,
|
||||
tariff: Union[bool, None] = None,
|
||||
trafficMessages: bool = False,
|
||||
travellerProfileData: Union[str, None] = None,
|
||||
withFreq: bool = True
|
||||
) -> dict:
|
||||
def trip_find(
|
||||
accessId: str,
|
||||
lang: Literal[
|
||||
"de", "da", "en", "es", "fr", "hu", "it", "nl", "no", "pl", "sv", "tr"
|
||||
] = "en",
|
||||
json: bool = True,
|
||||
originId: Union[str, None] = None,
|
||||
originExtId: Union[str, None] = None,
|
||||
originCoordLat: Union[str, float, None] = None,
|
||||
originCoordLong: Union[str, float, None] = None,
|
||||
originCoordName: Union[str, None] = None,
|
||||
destId: Union[str, None] = None,
|
||||
destExtId: Union[str, None] = None,
|
||||
destCoordLat: Union[str, float, None] = None,
|
||||
destCoordLong: Union[str, float, None] = None,
|
||||
destCoordName: Union[str, None] = None,
|
||||
via: Union[str, None] = None,
|
||||
viaId: Union[str, None] = None,
|
||||
viaWaitTime: int = 0,
|
||||
avoid: Union[str, None] = None,
|
||||
avoidId: Union[str, None] = None,
|
||||
viaGis: Union[str, None] = None,
|
||||
changeTimePercent: int = 100,
|
||||
minChangeTime: Union[int, None] = None,
|
||||
maxChangeTime: Union[int, None] = None,
|
||||
addChangeTime: Union[int, None] = None,
|
||||
maxChange: Union[int, None] = None,
|
||||
date: Union[str, datetime, None] = None,
|
||||
time: Union[str, datetime, None] = None,
|
||||
searchForArrival: bool = False,
|
||||
numF: Union[int, None] = None,
|
||||
numB: Union[int, None] = None,
|
||||
context: Union[str, None] = None,
|
||||
poly: bool = False,
|
||||
polyEnc: Literal["DLT", "GPA", "N"] = "N",
|
||||
passlist: bool = False,
|
||||
products: Union[int, None] = None,
|
||||
operators: Union[str, list, None] = None,
|
||||
attributes: Union[str, list, None] = None,
|
||||
sattributes: Union[str, list, None] = None,
|
||||
fattributes: Union[str, list, None] = None,
|
||||
lines: Union[str, list, None] = None,
|
||||
lineids: Union[str, list, None] = None,
|
||||
avoidPaths: Union[List[Literal["SW", "EA", "ES", "RA", "CB"]], None] = None,
|
||||
originWalk: Union[str, list, None] = None,
|
||||
originBike: Union[str, list, None] = None,
|
||||
originCar: Union[str, list, None] = None,
|
||||
originTaxi: Union[str, list, None] = None,
|
||||
originPark: Union[str, list, None] = None,
|
||||
originMeta: Union[str, list, None] = None,
|
||||
destWalk: Union[str, list, None] = None,
|
||||
destBike: Union[str, list, None] = None,
|
||||
destCar: Union[str, list, None] = None,
|
||||
destTaxi: Union[str, list, None] = None,
|
||||
destPark: Union[str, list, None] = None,
|
||||
destMeta: Union[str, list, None] = None,
|
||||
totalWalk: Union[str, list, None] = None,
|
||||
totalBike: Union[str, list, None] = None,
|
||||
totalCar: Union[str, list, None] = None,
|
||||
totalTaxi: Union[str, list, None] = None,
|
||||
totalMeta: Union[str, list, None] = None,
|
||||
gisProducts: Union[str, None] = None,
|
||||
includeIv: bool = False,
|
||||
ivOnly: bool = False,
|
||||
mobilityProfile: Union[str, None] = None,
|
||||
bikeCarriage: bool = False,
|
||||
bikeCarriageType: Union[
|
||||
Literal["SINGLEBIKES", "SMALLGROUPS", "LARGEGROUPS"], None
|
||||
] = None,
|
||||
sleepingCar: bool = False,
|
||||
couchetteCoach: bool = False,
|
||||
showPassingPoints: bool = False,
|
||||
baim: bool = False,
|
||||
eco: bool = False,
|
||||
ecoCmp: bool = False,
|
||||
ecoParams: Union[str, None] = None,
|
||||
rtMode: Union[Literal["FULL", "INFOS", "OFF", "REALTIME", "SERVER_DEFAULT"], None] = None,
|
||||
unsharp: bool = False,
|
||||
trainFilter: Union[str, None] = None,
|
||||
economic: bool = False,
|
||||
groupFilter: Union[str, None] = None,
|
||||
blockingList: Union[str, None] = None,
|
||||
blockedEdges: Union[str, None] = None,
|
||||
trainComposition: bool = False,
|
||||
includeEarlier: bool = False,
|
||||
withICTAlternatives: bool = False,
|
||||
tariff: Union[bool, None] = None,
|
||||
trafficMessages: bool = False,
|
||||
travellerProfileData: Union[str, None] = None,
|
||||
withFreq: bool = True,
|
||||
) -> dict:
|
||||
"""The trip service calculates a trip from a specified origin to a specified destination. These might be
|
||||
stop/station IDs or coordinates based on addresses and points of interest validated by the location service or
|
||||
coordinates freely defined by the client.
|
||||
coordinates freely defined by the client.
|
||||
|
||||
Read more about this in section 2.12. "Trip Search (trip)" of HAFAS ReST Documentation.
|
||||
Read more about this in section 2.12. "Trip Search (trip)" 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).
|
||||
@@ -217,14 +196,10 @@ def trip_find(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":
|
||||
@@ -235,10 +210,9 @@ def trip_find(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) == "rtMode":
|
||||
if val != None:
|
||||
payload["rtMode"] = val.upper()
|
||||
@@ -248,7 +222,4 @@ def trip_find(accessId: str,
|
||||
|
||||
output = get("https://www.rmv.de/hapi/trip", 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