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

@@ -5,4 +5,4 @@ from .journey_detail import journey_detail
from .stop_by_coords import stop_by_coords
from .stop_by_name import stop_by_name
from .trip_find import trip_find
from .trip_recon import trip_recon
from .trip_recon import trip_recon

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,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)

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)

View File

@@ -1,55 +1,58 @@
from requests import get
from typing import OrderedDict, Union
from xmltodict import parse as xmlparse
from datetime import datetime
from typing import OrderedDict, Union
from pyrmv.utility.weekdays_bitmask import weekdays_bitmask
from requests import get
from xmltodict import parse as xmlparse
from pyrmv.utility import weekdays_bitmask
try:
from typing import Literal
except ImportError:
from typing_extensions import Literal
# 2.37. HIM Search (himsearch)
def him_search(accessId: str,
json: bool = True,
dateB: Union[str, datetime, None] = None,
dateE: Union[str, datetime, None] = None,
timeB: Union[str, datetime, None] = None,
timeE: Union[str, datetime, None] = None,
weekdays: Union[str, OrderedDict[str, bool], None] = None,
himIds: Union[str, list, None] = None,
hierarchicalView: bool = False,
operators: Union[str, list, None] = None,
categories: Union[str, list, None] = None,
channels: Union[str, list, None] = None,
companies: Union[str, list, None] = None,
lines: Union[str, list, None] = None,
lineids: Union[str, list, None] = None,
stations: Union[str, list, None] = None,
fromstation: Union[str, None] = None,
tostation: Union[str, None] = None,
bothways: Union[bool, None] = None,
trainnames: Union[str, list, None] = None,
metas: Union[str, list, None] = None,
himcategory: Union[str, None] = None,
himtags: Union[str, list, None] = None,
regions: Union[str, list, None] = None,
himtext: Union[str, list, None] = None,
himtexttags: Union[str, list, None] = None,
additionalfields: Union[str, list, dict, None] = None,
poly: bool = False,
searchmode: Union[Literal["MATCH", "NOMATCH", "TFMATCH"], None] = None,
affectedJourneyMode: Union[Literal["ALL", "OFF"], None] = None,
affectedJourneyStopMode: Union[Literal["ALL", "IMP", "OFF"], None] = None,
orderBy: Union[str, list, None] = None,
minprio: Union[str, int, None] = None,
maxprio: Union[str, int, None] = None
) -> dict:
def him_search(
accessId: str,
json: bool = True,
dateB: Union[str, datetime, None] = None,
dateE: Union[str, datetime, None] = None,
timeB: Union[str, datetime, None] = None,
timeE: Union[str, datetime, None] = None,
weekdays: Union[str, OrderedDict[str, bool], None] = None,
himIds: Union[str, list, None] = None,
hierarchicalView: bool = False,
operators: Union[str, list, None] = None,
categories: Union[str, list, None] = None,
channels: Union[str, list, None] = None,
companies: Union[str, list, None] = None,
lines: Union[str, list, None] = None,
lineids: Union[str, list, None] = None,
stations: Union[str, list, None] = None,
fromstation: Union[str, None] = None,
tostation: Union[str, None] = None,
bothways: Union[bool, None] = None,
trainnames: Union[str, list, None] = None,
metas: Union[str, list, None] = None,
himcategory: Union[str, None] = None,
himtags: Union[str, list, None] = None,
regions: Union[str, list, None] = None,
himtext: Union[str, list, None] = None,
himtexttags: Union[str, list, None] = None,
additionalfields: Union[str, list, dict, None] = None,
poly: bool = False,
searchmode: Union[Literal["MATCH", "NOMATCH", "TFMATCH"], None] = None,
affectedJourneyMode: Union[Literal["ALL", "OFF"], None] = None,
affectedJourneyStopMode: Union[Literal["ALL", "IMP", "OFF"], None] = None,
orderBy: Union[str, list, None] = None,
minprio: Union[str, int, None] = None,
maxprio: Union[str, int, None] = None,
) -> dict:
"""The himSearch will return a list of HIM messages if matched by the given criteria as well as affected
products if any.
Read more about this in section 2.37. "HIM Search (himsearch)" of HAFAS ReST Documentation.
Read more about this in section 2.37. "HIM Search (himsearch)" 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).
@@ -89,28 +92,23 @@ def him_search(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) in ["dateB", "dateE"]:
if str(var) in {"dateB", "dateE"}:
if val != None:
if isinstance(val, datetime):
payload[str(var)] = val.strftime("%Y-%m-%d")
else:
payload[str(var)] = val
elif str(var) in ["timeB", "timeE"]:
elif str(var) in {"timeB", "timeE"}:
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) == "weekdays":
if val != None:
if isinstance(val, OrderedDict):
@@ -132,7 +130,4 @@ def him_search(accessId: str,
output = get("https://www.rmv.de/hapi/himsearch", params=payload, headers=headers)
if json:
return output.json()
else:
return xmlparse(output.content)
return output.json() if json else xmlparse(output.content)

View File

@@ -1,6 +1,7 @@
from datetime import datetime
from requests import get
from typing import Union
from requests import get
from xmltodict import parse as xmlparse
try:
@@ -8,27 +9,29 @@ try:
except ImportError:
from typing_extensions import Literal
# 2.26. Journey Detail (journeyDetail)
def journey_detail(accessId: str,
id: str,
json: bool = True,
date: Union[str, datetime, None] = None,
poly: bool = False,
polyEnc: Literal["DLT", "GPA", "N"] = "N",
showPassingPoints: bool = False,
rtMode: Union[Literal["FULL", "INFOS", "OFF", "REALTIME", "SERVER_DEFAULT"], None] = None,
fromId: Union[str, None] = None,
fromIdx: Union[int, None] = None,
toId: Union[str, None] = None,
toIdx: Union[int, None] = None,
baim: bool = False
) -> dict:
def journey_detail(
accessId: str,
id: str,
json: bool = True,
date: Union[str, datetime, None] = None,
poly: bool = False,
polyEnc: Literal["DLT", "GPA", "N"] = "N",
showPassingPoints: bool = False,
rtMode: Union[Literal["FULL", "INFOS", "OFF", "REALTIME", "SERVER_DEFAULT"], None] = None,
fromId: Union[str, None] = None,
fromIdx: Union[int, None] = None,
toId: Union[str, None] = None,
toIdx: Union[int, None] = None,
baim: bool = False,
) -> dict:
"""The journey_detail method will deliver information about the complete route of a vehicle. The journey
identifier is part of a trip or departureBoard response. It contains a list of all stops/stations of this journey
including all departure and arrival times (with real-time data if available) and additional information like
specific attributes about facilities and other texts.
specific attributes about facilities and other texts.
Read more about this in section 2.26. "Journey Detail (journeyDetail)" of HAFAS ReST Documentation.
Read more about this in section 2.26. "Journey Detail (journeyDetail)" 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).
@@ -47,14 +50,10 @@ def journey_detail(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) == "rtMode":
@@ -66,7 +65,4 @@ def journey_detail(accessId: str,
output = get("https://www.rmv.de/hapi/journeyDetail", params=payload, headers=headers)
if json:
return output.json()
else:
return xmlparse(output.content)
return output.json() if json else xmlparse(output.content)

View File

@@ -1,5 +1,6 @@
from requests import get
from typing import Union
from requests import get
from xmltodict import parse as xmlparse
try:
@@ -7,25 +8,29 @@ try:
except ImportError:
from typing_extensions import Literal
# 2.4. Location Search by Coordinate (location.nearbystops)
def stop_by_coords(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: Union[Literal["SLCT_N", "SLCT_A"], None] = None,
products: Union[int, None] = None,
meta: Union[str, None] = None,
sattributes: Union[str, list, None] = None,
sinfotexts: Union[str, list, None] = 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 section 2.4. "Location Search by Coordinate (location.nearbystops)" of HAFAS ReST Documentation.
# 2.4. Location Search by Coordinate (location.nearbystops)
def stop_by_coords(
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: Union[Literal["SLCT_N", "SLCT_A"], None] = None,
products: Union[int, None] = None,
meta: Union[str, None] = None,
sattributes: Union[str, list, None] = None,
sinfotexts: Union[str, list, None] = 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 section 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).
@@ -44,14 +49,10 @@ def stop_by_coords(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) == "stopType":
@@ -64,9 +65,8 @@ def stop_by_coords(accessId: str,
if val != None:
payload[str(var)] = val
output = get("https://www.rmv.de/hapi/location.nearbystops", params=payload, headers=headers)
output = get(
"https://www.rmv.de/hapi/location.nearbystops", params=payload, headers=headers
)
if json:
return output.json()
else:
return xmlparse(output.content)
return output.json() if json else xmlparse(output.content)

View File

@@ -1,5 +1,6 @@
from requests import get
from typing import Union
from requests import get
from xmltodict import parse as xmlparse
try:
@@ -7,33 +8,37 @@ try:
except ImportError:
from typing_extensions import Literal
# 2.3. Location Search by Name (location.name)
def stop_by_name(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: Union[Literal["SLCT_N", "SLCT_A"], None] = None,
products: Union[int, None] = None,
coordLat: Union[str, float, None] = None,
coordLong: Union[str, float, None] = None,
radius: Union[int, float] = 1000,
refineId: Union[str, None] = None,
meta: Union[str, None] = None,
stations: Union[str, list, None] = None,
sattributes: Union[str, list, None] = None,
filterMode: Literal["DIST_PERI", "EXCL_PERI", "SLCT_PERI"] = "DIST_PERI"
) -> dict:
def stop_by_name(
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: Union[Literal["SLCT_N", "SLCT_A"], None] = None,
products: Union[int, None] = None,
coordLat: Union[str, float, None] = None,
coordLong: Union[str, float, None] = None,
radius: Union[int, float] = 1000,
refineId: Union[str, None] = None,
meta: Union[str, None] = None,
stations: Union[str, list, None] = None,
sattributes: Union[str, list, None] = 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.
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).
location (stops/stations only).
Read more about this in section 2.3. "Location Search by Name (location.name)" of HAFAS ReST Documentation.
Read more about this in section 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).
@@ -55,14 +60,10 @@ def stop_by_name(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) == "inputString":
@@ -80,7 +81,4 @@ def stop_by_name(accessId: str,
output = get("https://www.rmv.de/hapi/location.name", params=payload, headers=headers)
if json:
return output.json()
else:
return xmlparse(output.content)
return output.json() if json else xmlparse(output.content)

View File

@@ -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)

View File

@@ -1,6 +1,7 @@
from datetime import datetime
from requests import get
from typing import Union
from requests import get
from xmltodict import parse as xmlparse
try:
@@ -8,43 +9,44 @@ try:
except ImportError:
from typing_extensions import Literal
# 2.17. Reconstruction (recon)
def trip_recon(accessId: str,
ctx: str,
json: bool = True,
poly: bool = False,
polyEnc: Literal["DLT", "GPA", "N"] = "N",
date: Union[str, datetime, None] = None,
useCombinedComparison: Union[bool, None] = None,
acceptGaps: Union[bool, None] = None,
allowDummySections: Union[bool, None] = None,
flagAllNonReachable: Union[bool, None] = None,
matchCatStrict: Union[bool, None] = None,
matchIdNonBlank: Union[bool, None] = None,
matchIdStrict: Union[bool, None] = None,
matchNumStrict: Union[bool, None] = None,
matchRtType: Union[bool, None] = None,
enableRtFullSearch: Union[bool, None] = None,
enableReplacements: Union[bool, None] = None,
arrL: Union[int, None] = None,
arrU: Union[int, None] = None,
depL: Union[int, None] = None,
depU: Union[int, None] = None,
passlist: bool = False,
showPassingPoints: bool = False,
rtMode: Union[Literal["FULL", "INFOS", "OFF", "REALTIME", "SERVER_DEFAULT"], None] = None,
eco: bool = False,
ecoCmp: bool = False,
ecoParams: Union[str, None] = None,
tariff: Union[bool, None] = None,
trafficMessages: Union[bool, None] = None,
travellerProfileData: Union[str, None] = None
) -> dict:
def trip_recon(
accessId: str,
ctx: str,
json: bool = True,
poly: bool = False,
polyEnc: Literal["DLT", "GPA", "N"] = "N",
date: Union[str, datetime, None] = None,
useCombinedComparison: Union[bool, None] = None,
acceptGaps: Union[bool, None] = None,
allowDummySections: Union[bool, None] = None,
flagAllNonReachable: Union[bool, None] = None,
matchCatStrict: Union[bool, None] = None,
matchIdNonBlank: Union[bool, None] = None,
matchIdStrict: Union[bool, None] = None,
matchNumStrict: Union[bool, None] = None,
matchRtType: Union[bool, None] = None,
enableRtFullSearch: Union[bool, None] = None,
enableReplacements: Union[bool, None] = None,
arrL: Union[int, None] = None,
arrU: Union[int, None] = None,
depL: Union[int, None] = None,
depU: Union[int, None] = None,
passlist: bool = False,
showPassingPoints: bool = False,
rtMode: Union[Literal["FULL", "INFOS", "OFF", "REALTIME", "SERVER_DEFAULT"], None] = None,
eco: bool = False,
ecoCmp: bool = False,
ecoParams: Union[str, None] = None,
tariff: Union[bool, None] = None,
trafficMessages: Union[bool, None] = None,
travellerProfileData: Union[str, None] = None,
) -> dict:
"""Reconstructing a trip can be achieved using the reconstruction context provided by any trip result in the
ctxRecon attribute of Trip element. The result will be a true copy of the original trip search result given
that the underlying data did not change.
that the underlying data did not change.
Read more about this in section 2.17. "Reconstruction (recon)" of HAFAS ReST Documentation.
Read more about this in section 2.17. "Reconstruction (recon)" 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).
@@ -80,14 +82,10 @@ def trip_recon(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":
@@ -102,7 +100,4 @@ def trip_recon(accessId: str,
output = get("https://www.rmv.de/hapi/recon", params=payload, headers=headers)
if json:
return output.json()
else:
return xmlparse(output.content)
return output.json() if json else xmlparse(output.content)