4 Commits

Author SHA1 Message Date
3461d82b34 Added list support 2022-10-06 14:35:10 +02:00
0d9ea775a6 Fixed small docstring issues 2022-10-06 14:34:54 +02:00
5613bf7e3f trip_recon made 2022-10-06 14:34:28 +02:00
2a83b34631 Small typo fix 2022-10-06 14:34:13 +02:00
10 changed files with 109 additions and 16 deletions

View File

@@ -45,7 +45,7 @@ def board_arrival(
* board_type (`Union[BoardArrivalType.ARR, BoardArrivalType.ARR_EQUIVS, BoardArrivalType.ARR_MAST, BoardArrivalType.ARR_STATION]`, optional): Set the station arrival board type to be used. Defaults to `BoardArrivalType.ARR`.
### Returns:
* BoardArrival: Instance of BoardArrival object.
* BoardArrival: Instance of `BoardArrival` object.
"""
if (isinstance(direction, Stop) or isinstance(direction, StopTrip)):

View File

@@ -45,7 +45,7 @@ def board_departure(
* board_type (`Union[BoardDepartureType.DEP, BoardDepartureType.DEP_EQUIVS, BoardDepartureType.DEP_MAST, BoardDepartureType.DEP_STATION]`, optional): Set the station departure board type to be used. Defaults to `BoardDepartureType.DEP`.
### Returns:
* BoardDeparture: Instance of BoardDeparture object.
* BoardDeparture: Instance of `BoardDeparture` object.
"""
if (isinstance(direction, Stop) or isinstance(direction, StopTrip)):

View File

@@ -39,7 +39,7 @@ def journey_detail(
* to_index (`int`, **optional**): Specifies the station/stop index the partial itinerary shall end at. Defaults to `None`.
### Returns:
* Journey: Instance of Journey object.
* Journey: Instance of `Journey` object.
"""
if real_time_mode == None:

View File

@@ -39,7 +39,7 @@ def stop_by_coords(
* selection_mode (`Literal[SelectionMode.SLCT_A, SelectionMode.SLCT_N]`, **optional**): Selection mode for locations. `SelectionMode.SLCT_N`: Not selectable, `SelectionMode.SLCT_A`: Selectable. Defaults to `None`.
### Returns:
* List[Stop]: List of Stop objects. Empty list if none found.
* List[Stop]: List of `Stop` objects. Empty list if none found.
"""
if selection_mode == None:

View File

@@ -23,7 +23,7 @@ def stop_by_id(
* lang (`Literal[Language.DE, Language.DA, Language.EN, Language.ES, Language.FR, Language.HU, Language.IT, Language.NL, Language.NO, Language.PL, Language.SV, Language.TR]`, **optional**): The language of response. Defaults to `Language.EN`.
### Returns:
* Stop: Instance of Stop object or None if not found.
* Stop: Instance of `Stop` object or `None` if not found.
"""
stops_raw = raw_stop_by_name(

View File

@@ -49,7 +49,7 @@ def stop_by_name(
* filter_mode (`Literal[FilterMode.DIST_PERI, FilterMode.EXCL_PERI, FilterMode.SLCT_PERI]`, **optional**): Filter modes for nearby searches. Defaults to `FilterMode.DIST_PERI`.
### Returns:
* List[Stop]: List of Stop objects. Empty list if none found.
* List[Stop]: List of `Stop` objects. Empty list if none found.
"""
if selection_mode == None:

View File

@@ -125,7 +125,7 @@ def trip_find(
* frequency (`bool`, **optional**): Enables/disables the calculation of frequency information. Defaults to `True`.
### Returns:
* List[Trip]: List of Trip objects. Empty list if none found.
* List[Trip]: List of `Trip` objects. Empty list if none found.
"""
if real_time_mode == None:

View File

@@ -1,5 +1,88 @@
from pyrmv.errors.not_ready import NotReadyYetError
from datetime import datetime
from typing import List, Union
from pyrmv.classes.Journey import Journey
from pyrmv.classes.Trip import Trip
from pyrmv.enums.rt_mode import RealTimeMode
from pyrmv.raw.trip_recon import trip_recon as raw_trip_recon
from pyrmv.utility.find_exception import find_exception
try:
from typing import Literal
except ImportError:
from typing_extensions import Literal
def trip_recon():
raise NotReadyYetError()
def trip_recon(
access_id: str,
context: Union[str, Journey],
date: Union[str, datetime] = None,
match_real_time: bool = None,
enable_replacements: bool = None,
arrival_dev_lower: int = None,
arrival_dev_upper: int = None,
departure_dev_lower: int = None,
departure_dev_upper: int = None,
passlist: bool = None,
passing_points: bool = False,
real_time_mode: Literal[RealTimeMode.FULL, RealTimeMode.INFOS, RealTimeMode.OFF, RealTimeMode.REALTIME, RealTimeMode.SERVER_DEFAULT] = None,
tariff: bool = None,
messages: bool = False
) -> List[Trip]:
"""Reconstructing a trip can be achieved using the reconstruction context provided by any trip result in the
`ctx_recon` attribute of `Trip` object. The result will be a true copy of the original trip search result given
that the underlying data did not change.
More detailed request is available as `raw.trip_recon()`, however returns `dict` instead of `List[Trip]`.
### Args:
* access_id (`str`): Access ID for identifying the requesting client. Get your key on [RMV website](https://opendata.rmv.de/site/start.html).
* context (`Union[str, Journey]`): Specifies the reconstruction context.
* date (`Union[str, datetime]`, **optional**): Sets the start date for which the departures shall be retrieved. Represented in the format `YYYY-MM-DD` or as a datetime object. This parameter will force the service to reconstruct the trip on that specific date. If the trip is not available on that date, because it does not operate, exception SvcNoResultError will be raised. Defaults to `None`.
* match_real_time (`bool`, **optional**): Whether the realtime type that journeys are based on be considered. Defaults to `None`.
* enable_replacements (`bool`, **optional**): If set to `True` replaces cancelled journeys with their replacement journeys if possible. Defaults to `None`.
* arrival_dev_lower (`int`, **optional**): Lower deviation in minutes within interval `[0, 720]` indicating "how much earlier than original arrival". Defaults to `None`.
* arrival_dev_upper (`int`, **optional**): Upper deviation in minutes within interval `[0, 720]` indicating "how much later than original arrival". Defaults to `None`.
* departure_dev_lower (`int`, **optional**): Lower deviation in minutes within interval `[0, 720]` indicating "how much earlier than original departure". Defaults to `None`.
* departure_dev_upper (`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 `None`.
* passing_points (`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`.
* real_time_mode (`Literal[RealTimeMode.FULL, RealTimeMode.INFOS, RealTimeMode.OFF, RealTimeMode.REALTIME, RealTimeMode.SERVER_DEFAULT]`, **optional**): Set the realtime mode to be used. Read more about this in HAFAS ReST Documentation. Defaults to `None`.
* tariff (`bool`, **optional**): Enables/disables the output of tariff data. The default is configurable via provisioning. Defaults to `None`.
* messages (`bool`, **optional**): Enables/disables the output of traffic messages. The default is configurable via provisioning. Defaults to `False`.
### Returns:
* List[Trip]: List of `Trip` objects. Empty list if none found.
"""
if real_time_mode == None:
real_time_mode = None
else:
real_time_mode = real_time_mode.code
if isinstance(context, Journey):
context = context.ctx_recon
trips = []
trips_raw = raw_trip_recon(
accessId=access_id,
ctx=context,
date=date,
matchRtType=match_real_time,
enableReplacements=enable_replacements,
arrL=arrival_dev_lower,
arrU=arrival_dev_upper,
depL=departure_dev_lower,
depU=departure_dev_upper,
passlist=passlist,
showPassingPoints=passing_points,
rtMode=real_time_mode,
tariff=tariff,
trafficMessages=messages,
)
find_exception(trips_raw)
for trip in trips_raw["Trip"]:
trips.append(Trip(trip))
return trips

View File

@@ -40,7 +40,7 @@ def trip_recon(accessId: str,
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
"""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.

16
test.py
View File

@@ -48,6 +48,12 @@ def test(name: str, data: Union[str, dict], raw: bool = False) -> None:
else:
with open(f"tests/{name}.txt", "w", encoding="utf-8") as file:
if isinstance(data, list):
list_2 = []
for item in data:
list_2.append(str(item)+"\n")
file.writelines(list_2)
else:
file.write(str(data))
file.close()
@@ -61,12 +67,16 @@ test("raw_board_arrival", pyrmv.raw.board_arrival(key, id="A=1@O=Offenbach (Main
test("raw_board_departure", pyrmv.raw.board_departure(key, id="A=1@O=Offenbach (Main)-Tempelsee Wilhelm-Schramm-Straße@X=8783648@Y=50083822@U=80@L=3008012@", maxJourneys=5), raw=True)
test("raw_him_search", pyrmv.raw.him_search(key, dateE=datetime.now()+timedelta(days=180), timeE=datetime.now()+timedelta(days=180), lines=["S1", "S9"], bothways=True, maxprio="1"), raw=True)
test("raw_journey_detail", pyrmv.raw.journey_detail(key, id="2|#VN#1#ST#1664906549#PI#0#ZI#12709#TA#0#DA#61022#1S#3008007#1T#1248#LS#3008043#LT#1323#PU#80#RT#1#CA#1aE#ZE#101#ZB#Bus 101 #PC#6#FR#3008007#FT#1248#TO#3008043#TT#1323#"), raw=True)
test("raw_stop_by_name", pyrmv.raw.stop_by_name(key, "Groß Karben", maxNo=5), raw=True)
test("raw_stop_by_coords", pyrmv.raw.stop_by_coords(key, 50.131140, 8.733362, radius=300, maxNo=5), raw=True)
test("raw_stop_by_name", pyrmv.raw.stop_by_name(key, "Groß Karben", maxNo=3), raw=True)
test("raw_stop_by_coords", pyrmv.raw.stop_by_coords(key, 50.131140, 8.733362, radius=300, maxNo=3), raw=True)
test("raw_trip_find", pyrmv.raw.trip_find(key, originCoordLat="50.084659", originCoordLong="8.785948", destCoordLat=50.1233048, destCoordLong=8.6129742, trafficMessages=True, numF=3), raw=True)
test("raw_trip_recon", pyrmv.raw.trip_recon(key, ctx="¶HKI¶G@F$A=2@O=50.084659, 8.785948@X=8785948@Y=50084659@u=0@a=128@$A=1@O=Offenbach (Main)-Tempelsee Wilhelm-Schramm-Straße@L=3008012@a=128@$202210061243$202210061247$$$1$$$$$$§T$A=1@O=Offenbach (Main)-Tempelsee Wilhelm-Schramm-Straße@L=3008012@a=128@$A=1@O=Offenbach (Main)-Zentrum Marktplatz\/Frankf. Straße@L=3002510@a=128@$202210061247$202210061300$Bus 101 $$1$$$$$$§W$A=1@O=Offenbach (Main)-Zentrum Marktplatz\/Frankf. Straße@L=3002510@a=128@$A=1@O=Offenbach (Main)-Zentrum Marktplatz@L=3011265@a=128@$202210061300$202210061304$$$1$$$$$$§T$A=1@O=Offenbach (Main)-Zentrum Marktplatz@L=3011265@a=128@$A=1@O=Frankfurt (Main) Taunusanlage@L=3000011@a=128@$202210061306$202210061319$ S2$$1$$$$$$§T$A=1@O=Frankfurt (Main) Taunusanlage@L=3000011@a=128@$A=1@O=Frankfurt (Main) Rödelheim Bahnhof@L=3001217@a=128@$202210061322$202210061333$ S5$$1$$$$$$§G@F$A=1@O=Frankfurt (Main) Rödelheim Bahnhof@L=3001217@a=128@$A=2@O=50.123304, 8.612974@X=8612974@Y=50123304@u=0@a=128@$202210061333$202210061344$$$1$$$$$$¶GP¶ft@0@2000@120@1@100@1@@0@@@@@false@0@-1@0@-1@-1@$f@$f@$f@$f@$f@$§bt@0@2000@120@1@100@1@@0@@@@@false@0@-1@0@-1@-1@$f@$f@$f@$f@$f@$§tt@0@2000@120@1@100@1@@0@@@@@false@0@-1@0@-1@-1@$f@$f@$f@$f@$f@$§¶KRCC¶#VE#1#"), raw=True)
test("stop_by_id", pyrmv.stop_by_id(key, "A=1@O=Offenbach (Main)-Zentrum Marktplatz\/Frankf. Straße@X=8764456@Y=50105181@U=80@L=3002510@"))
test("board_arrival", pyrmv.board_arrival(key, "A=1@O=Frankfurt (Main) Taunusanlage@X=8668765@Y=50113478@U=80@L=3000011@", journeys_max=5))
test("board_departure", pyrmv.board_departure(key, "A=1@O=Frankfurt (Main) Taunusanlage@X=8668765@Y=50113478@U=80@L=3000011@", journeys_max=5))
test("journey_detail", pyrmv.journey_detail(key, "2|#VN#1#ST#1664906549#PI#0#ZI#12709#TA#0#DA#61022#1S#3008007#1T#1248#LS#3008043#LT#1323#PU#80#RT#1#CA#1aE#ZE#101#ZB#Bus 101 #PC#6#FR#3008007#FT#1248#TO#3008043#TT#1323#", real_time_mode=RealTimeMode.FULL))
test("stop_by_coords", pyrmv.stop_by_coords(key, 50.131140, 8.733362, radius=300, max_number=3))
test("stop_by_id", pyrmv.stop_by_id(key, "A=1@O=Offenbach (Main)-Zentrum Marktplatz\/Frankf. Straße@X=8764456@Y=50105181@U=80@L=3002510@"))
test("stop_by_name", pyrmv.stop_by_name(key, "Groß Karben", max_number=3))
test("trip_find", pyrmv.trip_find(key, origin_coord_lat="50.084659", origin_coord_lon="8.785948", destination_coord_lat=50.1233048, destination_coord_lon=8.6129742, messages=True))
test("trip_recon", pyrmv.trip_recon(key, pyrmv.trip_find(key, origin_coord_lat="50.084659", origin_coord_lon="8.785948", destination_coord_lat=50.1233048, destination_coord_lon=8.6129742, messages=True, trips_after_time=1)[0] ))