Compare commits

...

2 Commits

Author SHA1 Message Date
7d5454a5df Removed unused imports and fixed docstring 2022-10-04 11:15:53 +02:00
013326d32a Added support for two new raw methods 2022-10-04 11:15:34 +02:00
3 changed files with 121 additions and 13 deletions

View File

@ -1,5 +1,6 @@
from datetime import datetime
from requests import get
from typing import List, Union
from typing import Union
from xmltodict import parse as xmlparse
try:
@ -9,8 +10,44 @@ except ImportError:
# 2.26. Journey Detail (journeyDetail)
def journey_detail(accessId: str,
json: bool = True
id: str,
json: bool = True,
date: Union[str, datetime] = None, # type: ignore
poly: bool = False,
polyEnc: Literal["DLT", "GPA", "N"] = "N",
showPassingPoints: bool = False,
rtMode: Literal["FULL", "INFOS", "OFF", "REALTIME", "SERVER_DEFAULT"] = None, # type: ignore
fromId: str = None, # type: ignore
fromIdx: str = None, # type: ignore
toId: str = None, # type: ignore
toIdx: str = None, # type: ignore
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.
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).
* id (str): Specifies the internal journey id of the journey shall be retrieved. Maximum length 512.
* json (bool, optional): Whether response should be retrieved as JSON. XML is returned if False. Defaults to True.
* date (Union[str, datetime], optional): Day of operation. Represented in the format `YYYY-MM-DD`. By default the current server date is used. Defaults to None.
* poly (bool, optional): Enables/disables the calculation of the polyline for each leg of the trip except any GIS route. Defaults to False.
* polyEnc (Literal["DLT", "GPA", "N"], optional): Defines encoding of the returned polyline. Possible values are "N" (no encoding / compression), "DLT" (delta to the previous coordinate), "GPA" (Google encoded polyline format). Defaults to "N".
* showPassingPoints (bool, optional): Enables/disables the return of stops having no alighting and no boarding in its passlist for each leg of the trip. Defaults to False.
* rtMode (Literal["FULL", "INFOS", "OFF", "REALTIME", "SERVER_DEFAULT"], optional): Set the realtime mode to be used. Read more about this in HAFAS ReST Documentation. Defaults to None.
* fromId (str, optional): Specifies the station/stop ID the partial itinerary shall start from. Defaults to None.
* fromIdx (str, optional): Specifies the station/stop index the partial itinerary shall start from. Defaults to None.
* toId (str, optional): Specifies the station/stop ID the partial itinerary shall end at. Defaults to None.
* toIdx (str, optional): Specifies the station/stop index the partial itinerary shall end at. Defaults to None.
* baim (bool, optional): Enables/disables BAIM search and response. Defaults to False.
### Returns:
* dict: Output from RMV. Dict will contain "errorCode" and "errorText" if exception occurs.
"""
if json:
headers = {"Accept": "application/json"}

View File

@ -2,9 +2,6 @@ from datetime import datetime
from requests import get
from typing import List, Union
from xmltodict import parse as xmlparse
from pyrmv.classes.Trip import Trip
from pyrmv.utility.find_exception import find_exception
try:
from typing import Literal
@ -127,7 +124,7 @@ def trip_find(accessId: str,
) -> 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.
@ -156,8 +153,8 @@ def trip_find(accessId: str,
* maxChangeTime (int, optional): Maximum change time at stop in minutes. Defaults to None.
* addChangeTime (int, optional): This amount of minutes is added to the change time at each stop. Defaults to None.
* maxChange (int, optional): Maximum number of changes. In range 0-11. Defaults to None.
* date (str, optional): Sets the start date for which the departures shall be retrieved. Represented in the format `YYYY-MM-DD`. By default the current server date is used. Defaults to None.
* time (str, optional): Sets the start time for which the departures shall be retrieved. Represented in the format `hh:mm[:ss]` in 24h nomenclature. Seconds will be ignored for requests. By default the current server time is used. Defaults to None.
* date (Union[str, datetime], optional): Sets the start date for which the departures shall be retrieved. Represented in the format `YYYY-MM-DD`. By default the current server date is used. Defaults to None.
* time (Union[str, datetime], optional): Sets the start time for which the departures shall be retrieved. Represented in the format `hh:mm[:ss]` in 24h nomenclature. Seconds will be ignored for requests. By default the current server time is used. Defaults to None.
* searchForArrival (bool, optional): If set, the date and time parameters specify the arrival time for the trip search instead of the departure time. Defaults to False.
* numF (int, optional): Minimum number of trips after the search time. Sum of numF and numB has to be less or equal 6. Read more about this in HAFAS ReST Documentation. In range 1-6. Defaults to None.
* numB (int, optional): Minimum number of trips before the search time. Sum of numF and numB has to be less or equal 6. Read more about this in HAFAS ReST Documentation. In range 0-6. Defaults to None.

View File

@ -1,9 +1,8 @@
from datetime import datetime
from requests import get
from typing import List, Union
from typing import Union
from xmltodict import parse as xmlparse
from pyrmv.utility.find_exception import find_exception
try:
from typing import Literal
except ImportError:
@ -11,8 +10,77 @@ except ImportError:
# 2.17. Reconstruction (recon)
def trip_recon(accessId: str,
json: bool = True
ctx: str,
json: bool = True,
poly: bool = False,
polyEnc: Literal["DLT", "GPA", "N"] = "N",
date: Union[str, datetime] = None, # type: ignore
useCombinedComparison: bool = None, # type: ignore
acceptGaps: bool = None, # type: ignore
allowDummySections: bool = None, # type: ignore
flagAllNonReachable: bool = None, # type: ignore
matchCatStrict: bool = None, # type: ignore
matchIdNonBlank: bool = None, # type: ignore
matchIdStrict: bool = None, # type: ignore
matchNumStrict: bool = None, # type: ignore
matchRtType: bool = None, # type: ignore
enableRtFullSearch: bool = None, # type: ignore
enableReplacements: bool = None, # type: ignore
arrL: int = None, # type: ignore
arrU: int = None, # type: ignore
depL: int = None, # type: ignore
depU: int = None, # type: ignore
passlist: bool = False,
showPassingPoints: bool = False,
rtMode: Literal["FULL", "INFOS", "OFF", "REALTIME", "SERVER_DEFAULT"] = None, # type: ignore
eco: bool = False,
ecoCmp: bool = False,
ecoParams: str = None, # type: ignore
tariff: bool = None, # type: ignore
trafficMessages: bool = None, # type: ignore
travellerProfileData: str = None # type: ignore
) -> dict:
"""Reconstructing a trip can be achieved using the resconstruction 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.
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).
* ctx (str): Specifies the reconstruction context.
* json (bool, optional): Whether response should be retrieved as JSON. XML is returned if False. Defaults to True.
* poly (bool, optional): Enables/disables the calculation of the polyline for each leg of the trip except any GIS route. Defaults to False.
* polyEnc (Literal["DLT", "GPA", "N"], optional): Defines encoding of the returned polyline. Possible values are "N" (no encoding / compression), "DLT" (delta to the previous coordinate), "GPA" (Google encoded polyline format). Defaults to "N".
* date (Union[str, datetime], optional): Sets the start date for which the departures shall be retrieved. Represented in the format `YYYY-MM-DD`. This parameter will force the ser-vice to reconstruct the trip on that specific date. If the trip is not available on that date, because it does not operate, the error code SVC_NO_RESULT will be returned. Defaults to None.
* useCombinedComparison (bool, optional): Compare based on combined output name - `False`: Compare parameters (category, line, train number) individually. Defaults to None.
* acceptGaps (bool, optional): Accept an incomplete description of the connection (with gaps) i.e. missing walks/transfers. Defaults to None.
* allowDummySections (bool, optional): Allow a partial reconstruction that will not lead to a reconstruction failure if sections are not reconstructable. Instead, for theses inconstructable sections, dummy sections will be created in the result. Defaults to None.
* flagAllNonReachable (bool, optional): Should all non-reachable journeys be flagged (`True`), or only the first one encountered? Defaults to None.
* matchCatStrict (bool, optional): Should the category (Gattung) match exactly? Only applicable if `useCombinedComparison` is `False`. Defaults to None.
* matchIdNonBlank (bool, optional): Should the train identifier (Zugbezeichner) without whitespace match? Defaults to None.
* matchIdStrict (bool, optional): Should the train identifier (Zugbezeichner) match exactly? Defaults to None.
* matchNumStrict (bool, optional): Should the train number (Zugnummer) match exactly? Only applicable if `useCombinedComparison` is `False`. Defaults to None.
* matchRtType (bool, optional): Should the realtime type that journeys are based on (e.g. SOLL, IST, additional, deviation, ) be considered? Defaults to None.
* enableRtFullSearch (bool, optional): By default, the reconstruction request makes one attempt for each journey within the scheduled data. However, the scheduled data may not necessarily reflect basic realtime properties of the journeys therein. In such a case, one may enable a two-step approach which we call "full search", i.e. search for matching journeys in the scheduled data in a first step. If this fails, then search for matching journeys in the realtime data. Defaults to None.
* enableReplacements (bool, optional): If set to true replaces cancelled journeys with their replacement journeys if possible. Defaults to None.
* arrL (int, optional): Lower deviation in minutes within interval [0, 720] indicating "how much earlier than original arrival". Defaults to None.
* arrU (int, optional): Upper deviation in minutes within interval [0, 720] indicating "how much later than original arrival". Defaults to None.
* depL (int, optional): Lower deviation in minutes within interval [0, 720] indicating "how much earlier than original departure". Defaults to None.
* depU (int, optional): Upper deviation in minutes within interval [0, 720] indicating "how much later than original departure". Defaults to None.
* passlist (bool, optional): Enables/disables the return of the passlist for each leg of the trip. Defaults to False.
* showPassingPoints (bool, optional): Enables/disables the return of stops having no alighting and boarding in its passlist for each leg of the trip. Needs passlist parameter enabled. Defaults to False.
* rtMode (Literal["FULL", "INFOS", "OFF", "REALTIME", "SERVER_DEFAULT"], optional): Set the realtime mode to be used. Read more about this in HAFAS ReST Documentation. Defaults to None.
* eco (bool, optional): Enables/disables eco value calculation. Defaults to False.
* ecoCmp (bool, optional): Enables/disables eco comparison. Defaults to False.
* ecoParams (str, optional): Provide additional eco parameters. Values vary. Defaults to None.
* tariff (bool, optional): Enables/disables the output of tariff data. The default is configurable via provisioning. Defaults to None.
* trafficMessages (bool, optional): Enables/disables the output of traffic messages. The default is configurable via provisioning. Defaults to None.
* travellerProfileData (str, optional): Traveller profile data. Structure depends on set up. Defaults to None.
### Returns:
* dict: Output from RMV. Dict will contain "errorCode" and "errorText" if exception occurs.
"""
if json:
headers = {"Accept": "application/json"}
@ -22,7 +90,13 @@ def trip_recon(accessId: str,
payload = {}
for var, val in locals().items():
if str(var) not in ["json", "headers", "payload"]:
if str(var) == "date":
if val != None:
if isinstance(val, datetime):
payload[str(var)] = val.strftime("%Y-%m-%d")
else:
payload[str(var)] = val
elif str(var) not in ["json", "headers", "payload"]:
if val != None:
payload[str(var)] = val