Initial commit #2

This commit is contained in:
Profitroll 2022-09-21 15:08:36 +02:00
parent 5f3be31d70
commit e89ea3e46f
5 changed files with 289 additions and 0 deletions

4
.gitignore vendored
View File

@ -152,3 +152,7 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
# Custom
tests
test_all.py

0
PythonRMV.py Normal file
View File

141
raw/findRoute.py Normal file
View File

@ -0,0 +1,141 @@
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)

65
raw/stopByCoords.py Normal file
View File

@ -0,0 +1,65 @@
from requests import get
from typing import Union
from xmltodict import parse as xmlparse
try:
from typing import Literal
except ImportError:
from typing_extensions import Literal
def stopByCoords(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: Literal["SLCT_N", "SLCT_A"] = None,
products: int = None,
meta: str = None,
sattributes: Union[str, list] = None,
sinfotexts: Union[str, list] = 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 paragraph 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).
* originCoordLat (Union[str, float]): Latitude of centre coordinate.
* originCoordLong (Union[str, float]): Longitude of centre coordinate.
* lang (Literal["de","da","en","es","fr","hu","it","nl","no","pl","sv","tr"], optional): The language of response. Defaults to "en".
* json (bool, optional): Whether response should be retrieved as JSON. XML is returned if False. Defaults to True.
* radius (Union[int, float], optional): Search radius in meter around the given coordinate if any. Defaults to 1000.
* maxNo (int, optional): Maximum number of returned stops. Defaults to 10.
* stopType (Literal["S", "P", "SP", "SE", "SPE"], optional): Type filter for location types. Defaults to "S".
* locationSelectionMode (Literal["SLCT_N", "SLCT_A"], optional): Selection mode for locations. Defaults to None.
* products (int, optional): Decimal value defining the product classes to be included in the search. It represents a bitmask combining bit number of a product as defined in the HAFAS raw data. Defaults to None.
* meta (str, optional): Filter by a predefined meta filter. If the rules of the predefined filter should not be negated, put ! in front of it. Defaults to None.
* sattributes (Union[str, list], optional): Filter locations by one or more attribute codes. Multiple attribute codes are separated by comma. If the attribute should not be part of the be location data, negate it by putting ! in front of it. Defaults to None.
* sinfotexts (Union[str, list], optional): Filter locations by one or more station infotext codes and values. Multiple attribute codes are separated by comma the value by pipe |. Defaults to None.
### 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 = {}
for var, val in locals().items():
if str(var) != "json":
if val != None:
payload[str(var)] = val
output = get("https://www.rmv.de/hapi/location.nearbystops", params=payload, headers=headers)
if json:
return output.json()
else:
return xmlparse(output.content)

79
raw/stopByName.py Normal file
View File

@ -0,0 +1,79 @@
from requests import get
from typing import Union
from xmltodict import parse as xmlparse
try:
from typing import Literal
except ImportError:
from typing_extensions import Literal
def stopByName(accessId: str,
inputString: str,
lang: Literal["de", "da", "en", "es", "fr", "hu", "it", "nl", "no", "pl", "sv", "tr"] = "en",
json: bool = True,
maxNo: int = 10,
stopType: Literal["A", "ALL", "AP", "P", "S", "SA", "SP"] = "ALL",
locationSelectionMode: Literal["SLCT_N", "SLCT_A"] = None,
products: int = None,
coordLat: Union[str, float] = None,
coordLong: Union[str, float] = None,
radius: Union[int, float] = 1000,
refineId: str = None,
meta: str = None,
stations: Union[str, list] = None,
sattributes: Union[str, list] = None,
filterMode: Literal["DIST_PERI", "EXCL_PERI", "SLCT_PERI"] = "DIST_PERI"
) -> dict:
"""The location.name service can be used to perform a pattern matching of a user input and to retrieve a list
of possible matches in the journey planner database. Possible matches might be stops/stations, points of
interest and addresses.
The result is a list of possible matches (locations) where the user might pick one entry to perform a trip
request with this location as origin or destination or to ask for a departure board or arrival board of this
location (stops/stations only).
Read more about this in paragraph 2.3. "Location Search by Name (location.name)" 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).
* inputString (str): Search for that token.
* lang (Literal["de","da","en","es","fr","hu","it","nl","no","pl","sv","tr"], optional): The language of response. Defaults to "en".
* json (bool, optional): Whether response should be retrieved as JSON. XML is returned if False. Defaults to True.
* maxNo (int, optional): Maximum number of returned stops. In range 1-1000. Defaults to 10.
* stopType (Literal["A", "ALL", "AP", "P", "S", "SA", "SP"], optional): Type filter for location types. Defaults to "ALL".
* locationSelectionMode (str, optional): Selection mode for locations. "SLCT_N": Not selectable, "SLCT_A": Selectable. Defaults to None.
* products (int, optional): Decimal value defining the product classes to be included in the search. It represents a bitmask combining bit number of a product as defined in the HAFAS raw data. Defaults to None.
* coordLat (Union[str, float], optional): Latitude of centre coordinate. Defaults to None.
* coordLong (Union[str, float], optional): Longitude of centre coordinate. Defaults to None.
* radius (Union[int, float], optional): Search radius in meter around the given coordinate if any. Defaults to 1000.
* refineId (str, optional): In case of an refinable location, this value takes the ID of the refinable one of a previous result. Defaults to None.
* meta (str, optional): Filter by a predefined meta filter. If the rules of the predefined filter should not be negated, put ! in front of it. Defaults to None.
* stations (Union[str, list], optional): Filter for stations. Matches if the given value is prefix of any station in the itinerary. Multiple values are separated by comma. Defaults to None.
* sattributes (Union[str, list], optional): Filter locations by one or more attribute codes. Multiple attribute codes are separated by comma. If the attribute should not be part of the be location data, negate it by putting ! in front of it. Defaults to None.
* filterMode (Literal["DIST_PERI", "EXCL_PERI", "SLCT_PERI"], optional): Filter modes for nearby searches. Defaults to "DIST_PERI".
### 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 = {}
for var, val in locals().items():
if str(var) == "inputString":
if val != None:
payload["input"] = val
elif str(var) != "json":
if val != None:
payload[str(var)] = val
output = get("https://www.rmv.de/hapi/location.name", params=payload, headers=headers)
if json:
return output.json()
else:
return xmlparse(output.content)