Compare commits

..

No commits in common. "e09e8f29fb71bd3499485cc0f65404385434e14d" and "9c9489aee1051e5c45782bd03741230793d2785d" have entirely different histories.

2 changed files with 66 additions and 66 deletions
pyrmv/classes
test.py

@ -57,7 +57,7 @@ class Client():
# Look for stops using all possible methods # Look for stops using all possible methods
stop_by_coords client.stop_by_coords(50.131140, 8.733362, radius=300, max_number=3) stop_by_coords client.stop_by_coords(50.131140, 8.733362, radius=300, max_number=3)
stop_by_id = client.stop_by_id("A=1@O=Offenbach (Main)-Zentrum Marktplatz/Frankf. Straße@X=8764456@Y=50105181@U=80@L=3002510@") stop_by_id = client.stop_by_id("A=1@O=Offenbach (Main)-Zentrum Marktplatz\/Frankf. Straße@X=8764456@Y=50105181@U=80@L=3002510@")
stop_by_name = client.stop_by_name("Groß Karben", max_number=3) stop_by_name = client.stop_by_name("Groß Karben", max_number=3)
# Find a trip and reconstruct it # Find a trip and reconstruct it
@ -110,10 +110,10 @@ class Client():
accessId=self.access_id, accessId=self.access_id,
id=id, id=id,
extId=id_ext, extId=id_ext,
direction=direction, # type: ignore direction=direction,
date=date, date=date,
time=time, time=time,
duration=duration, # type: ignore duration=duration,
maxJourneys=journeys_max, maxJourneys=journeys_max,
operators=operators, operators=operators,
lines=lines, lines=lines,
@ -166,10 +166,10 @@ class Client():
accessId=self.access_id, accessId=self.access_id,
id=id, id=id,
extId=id_ext, extId=id_ext,
direction=direction, # type: ignore direction=direction,
date=date, date=date,
time=time, time=time,
duration=duration, # type: ignore duration=duration,
maxJourneys=journeys_max, maxJourneys=journeys_max,
operators=operators, operators=operators,
lines=lines, lines=lines,
@ -182,28 +182,28 @@ class Client():
return BoardDeparture(board_raw, self) return BoardDeparture(board_raw, self)
def him_search(self, def him_search(self,
date_begin: Union[str, datetime] = None, # type: ignore date_begin: Union[str, datetime] = None,
date_end: Union[str, datetime] = None, # type: ignore date_end: Union[str, datetime] = None,
time_begin: Union[str, datetime] = None, # type: ignore time_begin: Union[str, datetime] = None,
time_end: Union[str, datetime] = None, # type: ignore time_end: Union[str, datetime] = None,
weekdays: Union[str, OrderedDict[str, bool]] = None, # type: ignore weekdays: Union[str, OrderedDict[str, bool]] = None,
ids: list = None, # type: ignore ids: list = None,
operators: list = None, # type: ignore operators: list = None,
categories: list = None, # type: ignore categories: list = None,
channels: list = None, # type: ignore channels: list = None,
companies: list = None, # type: ignore companies: list = None,
lines: list = None, # type: ignore lines: list = None,
line_ids: list = None, # type: ignore line_ids: list = None,
stations: Union[list, List[Stop]] = None, # type: ignore stations: Union[list, List[Stop]] = None,
station_from: Union[str, Stop] = None, # type: ignore station_from: Union[str, Stop] = None,
station_to: Union[str, Stop] = None, # type: ignore station_to: Union[str, Stop] = None,
both_ways: bool = None, # type: ignore both_ways: bool = None,
train_names: list = None, # type: ignore train_names: list = None,
search_mode: Literal[SearchMode.MATCH, SearchMode.NOMATCH, SearchMode.TFMATCH] = None, # type: ignore search_mode: Literal[SearchMode.MATCH, SearchMode.NOMATCH, SearchMode.TFMATCH] = None,
affected_journey_mode: Literal[AffectedJourneyMode.ALL, AffectedJourneyMode.OFF] = None, # type: ignore affected_journey_mode: Literal[AffectedJourneyMode.ALL, AffectedJourneyMode.OFF] = None,
affected_journey_stop_mode: Literal[AffectedJourneyStopMode.ALL, AffectedJourneyStopMode.IMP, AffectedJourneyStopMode.OFF] = None, # type: ignore affected_journey_stop_mode: Literal[AffectedJourneyStopMode.ALL, AffectedJourneyStopMode.IMP, AffectedJourneyStopMode.OFF] = None,
priority_min: int = None, # type: ignore priority_min: int = None,
priority_max: int = None # type: ignore priority_max: int = None
) -> List[Message]: ) -> List[Message]:
"""The him_search method will deliver a list of HIM messages if matched by the given criteria as """The him_search method will deliver a list of HIM messages if matched by the given criteria as
well as affected products if any. well as affected products if any.
@ -239,10 +239,10 @@ class Client():
""" """
if isinstance(station_from, Stop): if isinstance(station_from, Stop):
station_from = station_from.ext_id # type: ignore station_from = station_from.ext_id
if isinstance(station_to, Stop): if isinstance(station_to, Stop):
station_to = station_to.ext_id # type: ignore station_to = station_to.ext_id
if stations != None: if stations != None:
new_stations = [] new_stations = []
@ -254,17 +254,17 @@ class Client():
stations = new_stations stations = new_stations
if search_mode == None: if search_mode == None:
search_mode = None # type: ignore search_mode = None
else: else:
search_mode = search_mode.code search_mode = search_mode.code
if affected_journey_mode == None: if affected_journey_mode == None:
affected_journey_mode = None # type: ignore affected_journey_mode = None
else: else:
affected_journey_mode = affected_journey_mode.code affected_journey_mode = affected_journey_mode.code
if affected_journey_stop_mode == None: if affected_journey_stop_mode == None:
affected_journey_stop_mode = None # type: ignore affected_journey_stop_mode = None
else: else:
affected_journey_stop_mode = affected_journey_stop_mode.code affected_journey_stop_mode = affected_journey_stop_mode.code
@ -284,13 +284,13 @@ class Client():
lines=lines, lines=lines,
lineids=line_ids, lineids=line_ids,
stations=stations, stations=stations,
fromstation=station_from, # type: ignore fromstation=station_from,
tostation=station_to, # type: ignore tostation=station_to,
bothways=both_ways, bothways=both_ways,
trainnames=train_names, trainnames=train_names,
searchmode=search_mode, # type: ignore searchmode=search_mode,
affectedJourneyMode=affected_journey_mode, # type: ignore affectedJourneyMode=affected_journey_mode,
affectedJourneyStopMode=affected_journey_stop_mode, # type: ignore affectedJourneyStopMode=affected_journey_stop_mode,
maxprio=priority_max, maxprio=priority_max,
minprio=priority_min minprio=priority_min
) )
@ -332,7 +332,7 @@ class Client():
""" """
if real_time_mode == None: if real_time_mode == None:
real_time_mode = None # type: ignore real_time_mode = None
else: else:
real_time_mode = real_time_mode.code real_time_mode = real_time_mode.code
@ -340,11 +340,11 @@ class Client():
accessId=self.access_id, accessId=self.access_id,
id=id, id=id,
date=date, date=date,
rtMode=real_time_mode, # type: ignore rtMode=real_time_mode,
fromId=from_id, fromId=from_id,
fromIdx=from_index, # type: ignore fromIdx=from_index,
toId=to_id, toId=to_id,
toIdx=to_index # type: ignore toIdx=to_index
) )
find_exception(journey_raw) find_exception(journey_raw)
@ -380,7 +380,7 @@ class Client():
""" """
if selection_mode == None: if selection_mode == None:
selection_mode = None # type: ignore selection_mode = None
else: else:
selection_mode = selection_mode.code selection_mode = selection_mode.code
@ -393,7 +393,7 @@ class Client():
radius=radius, radius=radius,
maxNo=max_number, maxNo=max_number,
stopType=stop_type.code, stopType=stop_type.code,
locationSelectionMode=selection_mode # type: ignore locationSelectionMode=selection_mode
) )
find_exception(stops_raw) find_exception(stops_raw)
@ -478,7 +478,7 @@ class Client():
""" """
if selection_mode == None: if selection_mode == None:
selection_mode = None # type: ignore selection_mode = None
else: else:
selection_mode = selection_mode.code selection_mode = selection_mode.code
@ -489,7 +489,7 @@ class Client():
lang=lang.code, lang=lang.code,
maxNo=max_number, maxNo=max_number,
stopType=stop_type.code, stopType=stop_type.code,
locationSelectionMode=selection_mode, # type: ignore locationSelectionMode=selection_mode,
coordLat=coord_lat, coordLat=coord_lat,
coordLong=coord_lon, coordLong=coord_lon,
radius=radius, radius=radius,
@ -623,7 +623,7 @@ class Client():
""" """
if real_time_mode == None: if real_time_mode == None:
real_time_mode = None # type: ignore real_time_mode = None
else: else:
real_time_mode = real_time_mode.code real_time_mode = real_time_mode.code
@ -682,7 +682,7 @@ class Client():
showPassingPoints=passing_points, showPassingPoints=passing_points,
rtMode=real_time_mode, # type: ignore rtMode=real_time_mode,
includeEarlier=include_earlier, includeEarlier=include_earlier,
withICTAlternatives=ict_alternatives, withICTAlternatives=ict_alternatives,
@ -699,18 +699,18 @@ class Client():
return trips return trips
def trip_recon(self, def trip_recon(self,
context: Union[str, Trip], context: Union[str, Journey],
date: Union[str, datetime] = None, # type: ignore date: Union[str, datetime] = None,
match_real_time: bool = None, # type: ignore match_real_time: bool = None,
enable_replacements: bool = None, # type: ignore enable_replacements: bool = None,
arrival_dev_lower: int = None, # type: ignore arrival_dev_lower: int = None,
arrival_dev_upper: int = None, # type: ignore arrival_dev_upper: int = None,
departure_dev_lower: int = None, # type: ignore departure_dev_lower: int = None,
departure_dev_upper: int = None, # type: ignore departure_dev_upper: int = None,
passlist: bool = None, # type: ignore passlist: bool = None,
passing_points: bool = False, passing_points: bool = False,
real_time_mode: Literal[RealTimeMode.FULL, RealTimeMode.INFOS, RealTimeMode.OFF, RealTimeMode.REALTIME, RealTimeMode.SERVER_DEFAULT] = None, # type: ignore real_time_mode: Literal[RealTimeMode.FULL, RealTimeMode.INFOS, RealTimeMode.OFF, RealTimeMode.REALTIME, RealTimeMode.SERVER_DEFAULT] = None,
tariff: bool = None, # type: ignore tariff: bool = None,
messages: bool = False messages: bool = False
) -> List[Trip]: ) -> List[Trip]:
"""Reconstructing a trip can be achieved using the reconstruction 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
@ -739,7 +739,7 @@ class Client():
""" """
if real_time_mode == None: if real_time_mode == None:
real_time_mode = None # type: ignore real_time_mode = None
else: else:
real_time_mode = real_time_mode.code real_time_mode = real_time_mode.code
@ -749,7 +749,7 @@ class Client():
trips = [] trips = []
trips_raw = raw_trip_recon( trips_raw = raw_trip_recon(
accessId=self.access_id, accessId=self.access_id,
ctx=context, # type: ignore ctx=context,
date=date, date=date,
matchRtType=match_real_time, matchRtType=match_real_time,
enableReplacements=enable_replacements, enableReplacements=enable_replacements,
@ -759,7 +759,7 @@ class Client():
depU=departure_dev_upper, depU=departure_dev_upper,
passlist=passlist, passlist=passlist,
showPassingPoints=passing_points, showPassingPoints=passing_points,
rtMode=real_time_mode, # type: ignore rtMode=real_time_mode,
tariff=tariff, tariff=tariff,
trafficMessages=messages, trafficMessages=messages,
) )

10
test.py

@ -1,6 +1,6 @@
from datetime import datetime, timedelta from datetime import datetime, timedelta
from os import makedirs from os import makedirs
from typing import Any, Union from typing import Union
from ujson import loads, dumps, JSONDecodeError from ujson import loads, dumps, JSONDecodeError
from test_colors import * from test_colors import *
@ -24,7 +24,7 @@ except FileNotFoundError:
print("To skip entering your key every time create file 'test_key.json' with your apikey as a value for 'key' dict key.", flush=True) print("To skip entering your key every time create file 'test_key.json' with your apikey as a value for 'key' dict key.", flush=True)
def test(name: str, data: Any, raw: bool = False) -> None: def test(name: str, data: Union[str, dict], raw: bool = False) -> None:
makedirs("tests", exist_ok=True) makedirs("tests", exist_ok=True)
@ -56,7 +56,7 @@ def test(name: str, data: Any, raw: bool = False) -> None:
file.close() file.close()
if data in ["", "\n"]: if data in ["", "\n"]:
print(f"{BBLACK}[{BRED}ER{BBLACK}] {RESET}Test of {YELLOW}{name} {RESET}did not go well. ErrorCode is {BRED}{data['errorCode']}{RESET}. Check {CYAN}tests/{name}.txt {RESET}for more information.", flush=True) # type: ignore print(f"{BBLACK}[{BRED}ER{BBLACK}] {RESET}Test of {YELLOW}{name} {RESET}did not go well. ErrorCode is {BRED}{data['errorCode']}{RESET}. Check {CYAN}tests/{name}.txt {RESET}for more information.", flush=True)
else: else:
print(f"{BBLACK}[{BGREEN}OK{BBLACK}] {RESET}Test of {YELLOW}{name} {RESET}is not empty, so might be fine. Check {CYAN}tests/{name}.txt {RESET}for more information.", flush=True) print(f"{BBLACK}[{BGREEN}OK{BBLACK}] {RESET}Test of {YELLOW}{name} {RESET}is not empty, so might be fine. Check {CYAN}tests/{name}.txt {RESET}for more information.", flush=True)
@ -69,14 +69,14 @@ test("raw_journey_detail", pyrmv.raw.journey_detail(key, id="2|#VN#1#ST#16649065
test("raw_stop_by_name", pyrmv.raw.stop_by_name(key, "Groß Karben", maxNo=3), 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_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_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("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("board_arrival", client.board_arrival("A=1@O=Frankfurt (Main) Taunusanlage@X=8668765@Y=50113478@U=80@L=3000011@", journeys_max=5)) test("board_arrival", client.board_arrival("A=1@O=Frankfurt (Main) Taunusanlage@X=8668765@Y=50113478@U=80@L=3000011@", journeys_max=5))
test("board_departure", client.board_departure("A=1@O=Frankfurt (Main) Taunusanlage@X=8668765@Y=50113478@U=80@L=3000011@", journeys_max=5)) test("board_departure", client.board_departure("A=1@O=Frankfurt (Main) Taunusanlage@X=8668765@Y=50113478@U=80@L=3000011@", journeys_max=5))
test("him_search", client.him_search(date_end=datetime.now()+timedelta(days=10), priority_min=2, train_names=["S9"])) test("him_search", client.him_search(date_end=datetime.now()+timedelta(days=10), priority_min=2, train_names=["S9"]))
test("journey_detail", client.journey_detail("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=pyrmv.enums.RealTimeMode.FULL)) test("journey_detail", client.journey_detail("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=pyrmv.enums.RealTimeMode.FULL))
test("stop_by_coords", client.stop_by_coords(50.131140, 8.733362, radius=300, max_number=3)) test("stop_by_coords", client.stop_by_coords(50.131140, 8.733362, radius=300, max_number=3))
test("stop_by_id", client.stop_by_id("A=1@O=Offenbach (Main)-Zentrum Marktplatz/Frankf. Straße@X=8764456@Y=50105181@U=80@L=3002510@")) test("stop_by_id", client.stop_by_id("A=1@O=Offenbach (Main)-Zentrum Marktplatz\/Frankf. Straße@X=8764456@Y=50105181@U=80@L=3002510@"))
test("stop_by_name", client.stop_by_name("Groß Karben", max_number=3)) test("stop_by_name", client.stop_by_name("Groß Karben", max_number=3))
test("trip_find", client.trip_find(origin_coord_lat="50.084659", origin_coord_lon="8.785948", destination_coord_lat=50.1233048, destination_coord_lon=8.6129742, messages=True)) test("trip_find", client.trip_find(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", client.trip_recon( client.trip_find(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] )) test("trip_recon", client.trip_recon( client.trip_find(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] ))