PythonRMV/raw/findRoute.py
2022-09-21 15:08:36 +02:00

141 lines
3.9 KiB
Python

from requests import get
from typing import List, Union
from xmltodict import parse as xmlparse
try:
from typing import Literal
except ImportError:
from typing_extensions import Literal
def findRoute(accessId: str,
lang: str = None,
json: bool = True,
originId: str = None,
originExtId: str = None,
originCoordLat: Union[str, float] = None,
originCoordLong: Union[str, float] = None,
originCoordName: str = None,
destId: str = None,
destExtId: str = None,
destCoordLat: Union[str, float] = None,
destCoordLong: Union[str, float] = None,
destCoordName: str = None,
via: str = None,
viaId: str = None,
viaWaitTime: int = 0,
avoid: str = None,
avoidId: str = None,
viaGis: str = None,
changeTimePercent: int = 100,
minChangeTime: int = None,
maxChangeTime: int = None,
addChangeTime: int = None,
maxChange: int = None,
date: str = None,
time: str = None,
searchForArrival: bool = False,
numF: int = None,
numB: int = None,
context: str = None,
poly: bool = False,
polyEnc: Literal["DLT", "GPA", "N"] = "N",
passlist: bool = False,
products: str = None,
operators: Union[str, list] = None,
attributes: Union[str, list] = None,
sattributes: Union[str, list] = None,
fattributes: Union[str, list] = None,
lines: Union[str, list] = None,
lineids: Union[str, list] = None,
avoidPaths: List[Literal["SW", "EA", "ES", "RA", "CB"]] = None,
originWalk: Union[str, list] = None,
originBike: Union[str, list] = None,
originCar: Union[str, list] = None,
originTaxi: Union[str, list] = None,
originPark: Union[str, list] = None,
originMeta: Union[str, list] = None,
destWalk: Union[str, list] = None,
destBike: Union[str, list] = None,
destCar: Union[str, list] = None,
destTaxi: Union[str, list] = None,
destPark: Union[str, list] = None,
destMeta: Union[str, list] = None,
totalWalk: Union[str, list] = None,
totalBike: Union[str, list] = None,
totalCar: Union[str, list] = None,
totalTaxi: Union[str, list] = None,
totalMeta: Union[str, list] = None,
gisProducts: str = None,
includeIv: bool = False,
ivOnly: bool = False,
mobilityProfile: str = None,
bikeCarriage: bool = False,
bikeCarriageType: Literal["SINGLEBIKES", "SMALLGROUPS", "LARGEGROUPS"] = None,
sleepingCar: bool = False,
couchetteCoach: bool = False,
showPassingPoints: bool = False,
baim: bool = False,
eco: bool = False,
ecoCmp: bool = False,
ecoParams: str = None,
rtMode: Literal["FULL", "INFOS", "OFF", "REALTIME", "SERVER_DEFAULT"] = None,
unsharp: bool = False,
trainFilter: str = None,
economic: bool = False,
groupFilter: str = None,
blockingList: str = None,
blockedEdges: str = None,
trainComposition: bool = False,
includeEarlier: bool = False,
withICTAlternatives: bool = False,
tariff: bool = False,
trafficMessages: bool = False,
travellerProfileData: str = None,
withFreq: bool = True
) -> dict:
if json:
headers = {"Accept": "application/json"}
else:
headers = {"Accept": "application/xml"}
payload = {}
for var, val in locals().items():
if str(var) != "json":
if val != None:
payload[str(var)] = val
output = get("https://www.rmv.de/hapi/trip", params=payload, headers=headers)
if json:
return output.json()
else:
return xmlparse(output.content)