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:
Profitroll 2023-11-24 11:21:02 +01:00
parent fa4f7b83ec
commit f31fa65d78
Signed by: profitroll
GPG Key ID: FA35CAB49DACD3B2
45 changed files with 1035 additions and 923 deletions

View File

@ -1,4 +1,9 @@
# PythonRMV <h1 align="center">PythonRMV</h1>
<p align="center">
<a href="https://git.end-play.xyz/profitroll/PythonRMV/src/branch/master/LICENSE"><img alt="License: MIT" src="https://img.shields.io/badge/License-MIT-blue"></a>
<a href="https://git.end-play.xyz/profitroll/PythonRMV"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
</p>
Small module that makes your journey with RMV REST API somehow easier. Based fully on official RMV API reference and HAFAS documentation. Small module that makes your journey with RMV REST API somehow easier. Based fully on official RMV API reference and HAFAS documentation.

View File

@ -44,6 +44,7 @@ where = ["src"]
[tool.black] [tool.black]
target-version = ['py38', 'py39', 'py310', 'py311'] target-version = ['py38', 'py39', 'py310', 'py311']
line-length = 94
[tool.isort] [tool.isort]
profile = "black" profile = "black"

View File

@ -1,94 +1,99 @@
from datetime import datetime from datetime import datetime
from typing import Any, Mapping
from pyrmv.classes.Message import Message from pyrmv.classes.Message import Message
class LineArrival():
def __init__(self, data, client, retrieve_stops: bool = True): class LineArrival:
def __init__(self, data: Mapping[str, Any], client, retrieve_stops: bool = True):
self.journey = client.journey_detail(data["JourneyDetailRef"]["ref"]) self.journey = client.journey_detail(data["JourneyDetailRef"]["ref"])
self.status = data["JourneyStatus"] self.status = data["JourneyStatus"]
self.messages = [] self.messages = []
if "Messages" in data:
self.messages.extend(
Message(message) for message in data["Messages"]["Message"]
)
self.name = data["name"] self.name = data["name"]
self.type = data["type"] self.type = data["type"]
self.stop_name = data["stop"] self.stop_name = data["stop"]
self.stop_id = data["stopid"] self.stop_id = data["stopid"]
self.stop_id_ext = data["stopExtId"] self.stop_id_ext = data["stopExtId"]
if retrieve_stops: self.stop = client.stop_by_id(self.stop_id) if retrieve_stops else None
self.stop = client.stop_by_id(self.stop_id)
else:
self.stop = None
self.stop = client.stop_by_id(self.stop_id) self.stop = client.stop_by_id(self.stop_id)
self.time = datetime.strptime(data["time"], "%H:%M:%S") self.time = datetime.strptime(data["time"], "%H:%M:%S")
self.date = datetime.strptime(data["date"], "%Y-%m-%d") self.date = datetime.strptime(data["date"], "%Y-%m-%d")
if ("rtTime" in data) and ("rtDate" in data):
self.time_real_time = datetime.strptime(data["rtTime"], "%H:%M:%S")
self.date_real_time = datetime.strptime(data["rtDate"], "%Y-%m-%d")
self.reachable = data["reachable"] self.reachable = data["reachable"]
self.origin = data["origin"] self.origin = data["origin"]
self.origin = data["origin"]
if "Messages" in data:
self.messages.extend(Message(message) for message in data["Messages"]["Message"])
if ("rtTime" in data) and ("rtDate" in data):
self.time_real_time = datetime.strptime(data["rtTime"], "%H:%M:%S")
self.date_real_time = datetime.strptime(data["rtDate"], "%Y-%m-%d")
else:
self.time_real_time = None
self.date_real_time = None
def __str__(self) -> str: def __str__(self) -> str:
return f"{self.name} coming from {self.origin} at {self.time.time()} {self.date.date()}" return (
f"{self.name} coming from {self.origin} at {self.time.time()} {self.date.date()}"
)
class LineDeparture():
def __init__(self, data, client, retrieve_stops: bool = True): class LineDeparture:
def __init__(self, data: Mapping[str, Any], client, retrieve_stops: bool = True):
self.journey = client.journey_detail(data["JourneyDetailRef"]["ref"]) self.journey = client.journey_detail(data["JourneyDetailRef"]["ref"])
self.status = data["JourneyStatus"] self.status = data["JourneyStatus"]
self.messages = [] self.messages = []
if "Messages" in data:
self.messages.extend(
Message(message) for message in data["Messages"]["Message"]
)
self.name = data["name"] self.name = data["name"]
self.type = data["type"] self.type = data["type"]
self.stop_name = data["stop"] self.stop_name = data["stop"]
self.stop_id = data["stopid"] self.stop_id = data["stopid"]
self.stop_id_ext = data["stopExtId"] self.stop_id_ext = data["stopExtId"]
if retrieve_stops: self.stop = client.stop_by_id(self.stop_id) if retrieve_stops else None
self.stop = client.stop_by_id(self.stop_id)
else:
self.stop = None
self.time = datetime.strptime(data["time"], "%H:%M:%S") self.time = datetime.strptime(data["time"], "%H:%M:%S")
self.date = datetime.strptime(data["date"], "%Y-%m-%d") self.date = datetime.strptime(data["date"], "%Y-%m-%d")
if ("rtTime" in data) and ("rtDate" in data):
self.time_real_time = datetime.strptime(data["rtTime"], "%H:%M:%S")
self.date_real_time = datetime.strptime(data["rtDate"], "%Y-%m-%d")
self.reachable = data["reachable"] self.reachable = data["reachable"]
self.direction = data["direction"] self.direction = data["direction"]
self.direction_flag = data["directionFlag"] self.direction_flag = data["directionFlag"]
if "Messages" in data:
self.messages.extend(Message(message) for message in data["Messages"]["Message"])
if ("rtTime" in data) and ("rtDate" in data):
self.time_real_time = datetime.strptime(data["rtTime"], "%H:%M:%S")
self.date_real_time = datetime.strptime(data["rtDate"], "%Y-%m-%d")
else:
self.time_real_time = None
self.date_real_time = None
def __str__(self) -> str: def __str__(self) -> str:
return f"{self.name} heading {self.direction} at {self.time.time()} {self.date.date()}" return (
f"{self.name} heading {self.direction} at {self.time.time()} {self.date.date()}"
)
class BoardArrival(list): class BoardArrival(list):
def __init__(self, data: Mapping[str, Any], client, retrieve_stops: bool = True):
def __init__(self, data: dict, client, retrieve_stops: bool = True):
super().__init__([]) super().__init__([])
if "Arrival" not in data: if "Arrival" not in data:
return return
for line in data["Arrival"]: for line in data["Arrival"]:
self.append(LineArrival(line, client, retrieve_stops=retrieve_stops)) self.append(LineArrival(line, client, retrieve_stops=retrieve_stops))
def __str__(self) -> str: def __str__(self) -> str:
lines = [] return "Arrival board\n" + "\n".join([str(line) for line in self])
for line in self:
lines.append(str(line))
return "Arrival board\n" + "\n".join(lines)
class BoardDeparture(list): class BoardDeparture(list):
def __init__(self, data: Mapping[str, Any], client, retrieve_stops: bool = True):
def __init__(self, data: dict, client, retrieve_stops: bool = True):
super().__init__([]) super().__init__([])
if "Departure" not in data: if "Departure" not in data:
return return
for line in data["Departure"]: for line in data["Departure"]:
self.append(LineDeparture(line, client, retrieve_stops=retrieve_stops)) self.append(LineDeparture(line, client, retrieve_stops=retrieve_stops))
def __str__(self) -> str: def __str__(self) -> str:
lines = [] return "Departure board\n" + "\n".join([str(line) for line in self])
for line in self:
lines.append(str(line))
return "Departure board\n" + "\n".join(lines)

View File

@ -1,23 +1,25 @@
from datetime import datetime, timedelta from datetime import datetime, timedelta
from typing import List, OrderedDict, Union from typing import List, OrderedDict, Union
from pyrmv.classes import * from pyrmv.classes import *
from pyrmv.enums import * from pyrmv.enums import *
from pyrmv.raw import board_arrival as raw_board_arrival from pyrmv.raw import board_arrival as raw_board_arrival
from pyrmv.raw.board_departure import board_departure as raw_board_departure from pyrmv.raw.board_departure import board_departure as raw_board_departure
from pyrmv.raw.him_search import him_search as raw_him_search
from pyrmv.raw.journey_detail import journey_detail as raw_journey_detail from pyrmv.raw.journey_detail import journey_detail as raw_journey_detail
from pyrmv.raw.stop_by_name import stop_by_name as raw_stop_by_name
from pyrmv.raw.stop_by_coords import stop_by_coords as raw_stop_by_coords from pyrmv.raw.stop_by_coords import stop_by_coords as raw_stop_by_coords
from pyrmv.raw.stop_by_name import stop_by_name as raw_stop_by_name
from pyrmv.raw.trip_find import trip_find as raw_trip_find from pyrmv.raw.trip_find import trip_find as raw_trip_find
from pyrmv.raw.trip_recon import trip_recon as raw_trip_recon from pyrmv.raw.trip_recon import trip_recon as raw_trip_recon
from pyrmv.raw.him_search import him_search as raw_him_search from pyrmv.utility import find_exception
from pyrmv.utility.find_exception import find_exception
try: try:
from typing import Literal from typing import Literal
except ImportError: except ImportError:
from typing_extensions import Literal from typing_extensions import Literal
class Client():
class Client:
"""The main class in the whole module. Is used to use all non-raw methods. """The main class in the whole module. Is used to use all non-raw methods.
More detailed docs for each method can be found by using IDE's docstring More detailed docs for each method can be found by using IDE's docstring
@ -69,7 +71,8 @@ class Client():
def __init__(self, access_id: str) -> None: def __init__(self, access_id: str) -> None:
self.access_id = access_id self.access_id = access_id
def board_arrival(self, def board_arrival(
self,
id: Union[str, None] = None, id: Union[str, None] = None,
id_ext: Union[str, None] = None, id_ext: Union[str, None] = None,
direction: Union[str, Stop, StopTrip, None] = None, direction: Union[str, Stop, StopTrip, None] = None,
@ -80,8 +83,13 @@ class Client():
operators: Union[str, list, None] = None, operators: Union[str, list, None] = None,
lines: Union[str, list, None] = None, lines: Union[str, list, None] = None,
passlist: bool = False, passlist: bool = False,
board_type: Literal[BoardArrivalType.ARR, BoardArrivalType.ARR_EQUIVS, BoardArrivalType.ARR_MAST, BoardArrivalType.ARR_STATION] = BoardArrivalType.ARR, board_type: Literal[
retrieve_stops: bool = True BoardArrivalType.ARR,
BoardArrivalType.ARR_EQUIVS,
BoardArrivalType.ARR_MAST,
BoardArrivalType.ARR_STATION,
] = BoardArrivalType.ARR,
retrieve_stops: bool = True,
) -> BoardArrival: ) -> BoardArrival:
"""Method returns a board with arriving transport. """Method returns a board with arriving transport.
@ -105,7 +113,7 @@ class Client():
* BoardArrival: Instance of `BoardArrival` object. * BoardArrival: Instance of `BoardArrival` object.
""" """
if (isinstance(direction, Stop) or isinstance(direction, StopTrip)): if isinstance(direction, Stop) or isinstance(direction, StopTrip):
direction = direction.id direction = direction.id
board_raw = raw_board_arrival( board_raw = raw_board_arrival(
@ -120,14 +128,15 @@ class Client():
operators=operators, operators=operators,
lines=lines, lines=lines,
passlist=passlist, passlist=passlist,
boardType=board_type.code boardType=board_type.code,
) )
find_exception(board_raw) find_exception(board_raw)
return BoardArrival(board_raw, self, retrieve_stops=retrieve_stops) return BoardArrival(board_raw, self, retrieve_stops=retrieve_stops)
def board_departure(self, def board_departure(
self,
id: Union[str, None] = None, id: Union[str, None] = None,
id_ext: Union[str, None] = None, id_ext: Union[str, None] = None,
direction: Union[str, Stop, StopTrip, None] = None, direction: Union[str, Stop, StopTrip, None] = None,
@ -138,8 +147,13 @@ class Client():
operators: Union[str, list, None] = None, operators: Union[str, list, None] = None,
lines: Union[str, list, None] = None, lines: Union[str, list, None] = None,
passlist: bool = False, passlist: bool = False,
board_type: Literal[BoardDepartureType.DEP, BoardDepartureType.DEP_EQUIVS, BoardDepartureType.DEP_MAST, BoardDepartureType.DEP_STATION] = BoardDepartureType.DEP, board_type: Literal[
retrieve_stops: bool = True BoardDepartureType.DEP,
BoardDepartureType.DEP_EQUIVS,
BoardDepartureType.DEP_MAST,
BoardDepartureType.DEP_STATION,
] = BoardDepartureType.DEP,
retrieve_stops: bool = True,
) -> BoardDeparture: ) -> BoardDeparture:
"""Method returns a board with departing transport. """Method returns a board with departing transport.
@ -163,7 +177,7 @@ class Client():
* BoardDeparture: Instance of `BoardDeparture` object. * BoardDeparture: Instance of `BoardDeparture` object.
""" """
if (isinstance(direction, Stop) or isinstance(direction, StopTrip)): if isinstance(direction, (Stop, StopTrip)):
direction = direction.id direction = direction.id
board_raw = raw_board_departure( board_raw = raw_board_departure(
@ -178,14 +192,15 @@ class Client():
operators=operators, operators=operators,
lines=lines, lines=lines,
passlist=passlist, passlist=passlist,
boardType=board_type.code boardType=board_type.code,
) )
find_exception(board_raw) find_exception(board_raw)
return BoardDeparture(board_raw, self, retrieve_stops=retrieve_stops) return BoardDeparture(board_raw, self, retrieve_stops=retrieve_stops)
def him_search(self, def him_search(
self,
date_begin: Union[str, datetime, None] = None, date_begin: Union[str, datetime, None] = None,
date_end: Union[str, datetime, None] = None, date_end: Union[str, datetime, None] = None,
time_begin: Union[str, datetime, None] = None, time_begin: Union[str, datetime, None] = None,
@ -203,11 +218,22 @@ class Client():
station_to: Union[str, Stop, None] = None, station_to: Union[str, Stop, None] = None,
both_ways: Union[bool, None] = None, both_ways: Union[bool, None] = None,
train_names: Union[list, None] = None, train_names: Union[list, None] = None,
search_mode: Union[Literal[SearchMode.MATCH, SearchMode.NOMATCH, SearchMode.TFMATCH], None] = None, search_mode: Union[
affected_journey_mode: Union[Literal[AffectedJourneyMode.ALL, AffectedJourneyMode.OFF], None] = None, Literal[SearchMode.MATCH, SearchMode.NOMATCH, SearchMode.TFMATCH], None
affected_journey_stop_mode: Union[Literal[AffectedJourneyStopMode.ALL, AffectedJourneyStopMode.IMP, AffectedJourneyStopMode.OFF], None] = None, ] = None,
affected_journey_mode: Union[
Literal[AffectedJourneyMode.ALL, AffectedJourneyMode.OFF], None
] = None,
affected_journey_stop_mode: Union[
Literal[
AffectedJourneyStopMode.ALL,
AffectedJourneyStopMode.IMP,
AffectedJourneyStopMode.OFF,
],
None,
] = None,
priority_min: Union[int, None] = None, priority_min: Union[int, None] = None,
priority_max: Union[int, None] = None priority_max: Union[int, None] = 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.
@ -257,20 +283,13 @@ class Client():
new_stations.append(stop) new_stations.append(stop)
stations = new_stations stations = new_stations
if search_mode == None: search_mode = None if search_mode is None else search_mode.code
search_mode = None affected_journey_mode = (
else: None if affected_journey_mode is None else affected_journey_mode.code
search_mode = search_mode.code )
affected_journey_stop_mode = (
if affected_journey_mode == None: None if affected_journey_stop_mode is None else affected_journey_stop_mode.code
affected_journey_mode = None )
else:
affected_journey_mode = affected_journey_mode.code
if affected_journey_stop_mode == None:
affected_journey_stop_mode = None
else:
affected_journey_stop_mode = affected_journey_stop_mode.code
messages = [] messages = []
messages_raw = raw_him_search( messages_raw = raw_him_search(
@ -296,25 +315,34 @@ class Client():
affectedJourneyMode=affected_journey_mode, # type: ignore affectedJourneyMode=affected_journey_mode, # type: ignore
affectedJourneyStopMode=affected_journey_stop_mode, # type: ignore affectedJourneyStopMode=affected_journey_stop_mode, # type: ignore
maxprio=priority_max, maxprio=priority_max,
minprio=priority_min minprio=priority_min,
) )
find_exception(messages_raw) find_exception(messages_raw)
if "Message" in messages_raw: if "Message" in messages_raw:
for message in messages_raw["Message"]: messages.extend(Message(message) for message in messages_raw["Message"])
messages.append(Message(message))
return messages return messages
def journey_detail(self, def journey_detail(
self,
id: str, id: str,
date: Union[str, datetime, None] = None, date: Union[str, datetime, None] = None,
real_time_mode: Union[Literal[RealTimeMode.FULL, RealTimeMode.INFOS, RealTimeMode.OFF, RealTimeMode.REALTIME, RealTimeMode.SERVER_DEFAULT], None] = None, real_time_mode: Union[
Literal[
RealTimeMode.FULL,
RealTimeMode.INFOS,
RealTimeMode.OFF,
RealTimeMode.REALTIME,
RealTimeMode.SERVER_DEFAULT,
],
None,
] = None,
from_id: Union[str, None] = None, from_id: Union[str, None] = None,
from_index: Union[int, None] = None, from_index: Union[int, None] = None,
to_id: Union[str, None] = None, to_id: Union[str, None] = None,
to_index: Union[int, None] = None to_index: Union[int, None] = None,
) -> Journey: ) -> Journey:
"""The journey_detail method will deliver information about the complete route of a vehicle. The journey """The journey_detail method will deliver information about the complete route of a vehicle. The journey
identifier is part of a trip or `board_departure()` response. It contains a list of all stops/stations of this journey identifier is part of a trip or `board_departure()` response. It contains a list of all stops/stations of this journey
@ -336,10 +364,7 @@ class Client():
* Journey: Instance of `Journey` object. * Journey: Instance of `Journey` object.
""" """
if real_time_mode == None: real_time_mode = None if real_time_mode is None else real_time_mode.code
real_time_mode = None
else:
real_time_mode = real_time_mode.code
journey_raw = raw_journey_detail( journey_raw = raw_journey_detail(
accessId=self.access_id, accessId=self.access_id,
@ -349,22 +374,43 @@ class Client():
fromId=from_id, fromId=from_id,
fromIdx=from_index, fromIdx=from_index,
toId=to_id, toId=to_id,
toIdx=to_index toIdx=to_index,
) )
find_exception(journey_raw) find_exception(journey_raw)
return Journey(journey_raw) return Journey(journey_raw)
def stop_by_coords(self, def stop_by_coords(
self,
coords_lat: Union[str, float], coords_lat: Union[str, float],
coords_lon: Union[str, float], coords_lon: Union[str, float],
lang: Literal[
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] = Language.EN, Language.DE,
Language.DA,
Language.EN,
Language.ES,
Language.FR,
Language.HU,
Language.IT,
Language.NL,
Language.NO,
Language.PL,
Language.SV,
Language.TR,
] = Language.EN,
radius: Union[int, float] = 1000, radius: Union[int, float] = 1000,
max_number: int = 10, max_number: int = 10,
stop_type: Literal[LocationType.S, LocationType.P, LocationType.SP, LocationType.SE, LocationType.SPE] = LocationType.S, stop_type: Literal[
selection_mode: Union[Literal[SelectionMode.SLCT_A, SelectionMode.SLCT_N], None] = None, LocationType.S,
LocationType.P,
LocationType.SP,
LocationType.SE,
LocationType.SPE,
] = LocationType.S,
selection_mode: Union[
Literal[SelectionMode.SLCT_A, SelectionMode.SLCT_N], None
] = None,
) -> List[Stop]: ) -> List[Stop]:
"""Method returns a list of stops around a given center coordinate. """Method returns a list of stops around a given center coordinate.
The returned results are ordered by their distance to the center coordinate. The returned results are ordered by their distance to the center coordinate.
@ -384,10 +430,7 @@ class Client():
* 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: selection_mode = None if selection_mode is None else selection_mode.code
selection_mode = None
else:
selection_mode = selection_mode.code
stops = [] stops = []
stops_raw = raw_stop_by_coords( stops_raw = raw_stop_by_coords(
@ -398,7 +441,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, # type: ignore
) )
find_exception(stops_raw) find_exception(stops_raw)
@ -412,9 +455,23 @@ class Client():
return stops return stops
def stop_by_id(self, def stop_by_id(
self,
query: str, query: str,
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] = Language.EN, 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,
] = Language.EN,
) -> Union[Stop, None]: ) -> Union[Stop, None]:
"""Method can be used to get Stop object whilst only having id available. """Method can be used to get Stop object whilst only having id available.
@ -427,15 +484,14 @@ class Client():
""" """
stops_raw = raw_stop_by_name( stops_raw = raw_stop_by_name(
accessId=self.access_id, accessId=self.access_id, inputString=query, lang=lang.code, maxNo=1
inputString=query,
lang=lang.code,
maxNo=1
) )
find_exception(stops_raw) find_exception(stops_raw)
if len(stops_raw["stopLocationOrCoordLocation"]) > 0: if len(stops_raw["stopLocationOrCoordLocation"]) <= 0:
return None
stop = stops_raw["stopLocationOrCoordLocation"][0] stop = stops_raw["stopLocationOrCoordLocation"][0]
if "StopLocation" in stop: if "StopLocation" in stop:
@ -444,21 +500,45 @@ class Client():
return Stop(stop["CoordLocation"]) return Stop(stop["CoordLocation"])
else: else:
return None return None
else:
return None
def stop_by_name(self, def stop_by_name(
self,
query: str, query: str,
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] = Language.EN, 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,
] = Language.EN,
max_number: int = 10, max_number: int = 10,
stop_type: Literal[LocationType.A, LocationType.ALL, LocationType.AP, LocationType.P, LocationType.S, LocationType.SA, LocationType.SP] = LocationType.ALL, stop_type: Literal[
selection_mode: Union[Literal[SelectionMode.SLCT_A, SelectionMode.SLCT_N], None] = None, LocationType.A,
LocationType.ALL,
LocationType.AP,
LocationType.P,
LocationType.S,
LocationType.SA,
LocationType.SP,
] = LocationType.ALL,
selection_mode: Union[
Literal[SelectionMode.SLCT_A, SelectionMode.SLCT_N], None
] = None,
coord_lat: Union[str, float, None] = None, coord_lat: Union[str, float, None] = None,
coord_lon: Union[str, float, None] = None, coord_lon: Union[str, float, None] = None,
radius: Union[int, float] = 1000, radius: Union[int, float] = 1000,
refine_id: Union[str, None] = None, refine_id: Union[str, None] = None,
stations: Union[str, list, None] = None, stations: Union[str, list, None] = None,
filter_mode: Literal[FilterMode.DIST_PERI, FilterMode.EXCL_PERI, FilterMode.SLCT_PERI] = FilterMode.DIST_PERI filter_mode: Literal[
FilterMode.DIST_PERI, FilterMode.EXCL_PERI, FilterMode.SLCT_PERI
] = FilterMode.DIST_PERI,
) -> List[Stop]: ) -> List[Stop]:
"""Method can be used to perform a pattern matching of a user input and to retrieve a list """Method 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, of possible matches in the journey planner database. Possible matches might be stops/stations,
@ -483,10 +563,7 @@ class Client():
* 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: selection_mode = None if selection_mode is None else selection_mode.code
selection_mode = None
else:
selection_mode = selection_mode.code
stops = [] stops = []
stops_raw = raw_stop_by_name( stops_raw = raw_stop_by_name(
@ -501,7 +578,7 @@ class Client():
radius=radius, radius=radius,
refineId=refine_id, refineId=refine_id,
stations=stations, stations=stations,
filterMode=filter_mode.code filterMode=filter_mode.code,
) )
find_exception(stops_raw) find_exception(stops_raw)
@ -515,65 +592,72 @@ class Client():
return stops return stops
def trip_find(self, def trip_find(
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] = Language.EN, self,
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,
] = Language.EN,
origin_id: Union[str, None] = None, origin_id: Union[str, None] = None,
origin_id_ext: Union[str, None] = None, origin_id_ext: Union[str, None] = None,
origin_coord_lat: Union[str, float, None] = None, origin_coord_lat: Union[str, float, None] = None,
origin_coord_lon: Union[str, float, None] = None, origin_coord_lon: Union[str, float, None] = None,
origin_coord_name: Union[str, None] = None, origin_coord_name: Union[str, None] = None,
destination_id: Union[str, None] = None, destination_id: Union[str, None] = None,
destination_id_ext: Union[str, None] = None, destination_id_ext: Union[str, None] = None,
destination_coord_lat: Union[str, float, None] = None, destination_coord_lat: Union[str, float, None] = None,
destination_coord_lon: Union[str, float, None] = None, destination_coord_lon: Union[str, float, None] = None,
destination_coord_name: Union[str, None] = None, destination_coord_name: Union[str, None] = None,
via: Union[str, None] = None, via: Union[str, None] = None,
via_id: Union[str, None] = None, via_id: Union[str, None] = None,
via_gis: Union[str, None] = None, via_gis: Union[str, None] = None,
via_wait_time: int = 0, via_wait_time: int = 0,
avoid: Union[str, None] = None, avoid: Union[str, None] = None,
avoid_id: Union[str, None] = None, avoid_id: Union[str, None] = None,
change_time_percent: int = 100, change_time_percent: int = 100,
change_time_min: Union[int, None] = None, change_time_min: Union[int, None] = None,
change_time_max: Union[int, None] = None, change_time_max: Union[int, None] = None,
change_time_add: Union[int, None] = None, change_time_add: Union[int, None] = None,
change_max: Union[int, None] = None, change_max: Union[int, None] = None,
date: Union[str, datetime, None] = None, date: Union[str, datetime, None] = None,
time: Union[str, datetime, None] = None, time: Union[str, datetime, None] = None,
search_arrival: bool = False, search_arrival: bool = False,
trips_after_time: Union[int, None] = None, trips_after_time: Union[int, None] = None,
trips_before_time: Union[int, None] = None, trips_before_time: Union[int, None] = None,
context: Union[str, None] = None, context: Union[str, None] = None,
passlist: bool = False, passlist: bool = False,
operators: Union[str, list, None] = None, operators: Union[str, list, None] = None,
lines: Union[str, list, None] = None, lines: Union[str, list, None] = None,
lineids: Union[str, list, None] = None, lineids: Union[str, list, None] = None,
iv_include: bool = False, iv_include: bool = False,
iv_only: bool = False, iv_only: bool = False,
bike_carriage: bool = False, bike_carriage: bool = False,
passing_points: bool = False, passing_points: bool = False,
real_time_mode: Union[
real_time_mode: Union[Literal[RealTimeMode.FULL, RealTimeMode.INFOS, RealTimeMode.OFF, RealTimeMode.REALTIME, RealTimeMode.SERVER_DEFAULT], None] = None, Literal[
RealTimeMode.FULL,
RealTimeMode.INFOS,
RealTimeMode.OFF,
RealTimeMode.REALTIME,
RealTimeMode.SERVER_DEFAULT,
],
None,
] = None,
include_earlier: bool = False, include_earlier: bool = False,
ict_alternatives: bool = False, ict_alternatives: bool = False,
tariff: Union[bool, None] = None, tariff: Union[bool, None] = None,
messages: bool = False, messages: bool = False,
frequency: bool = True frequency: bool = True,
) -> List[Trip]: ) -> List[Trip]:
"""The trip service calculates a trip from a specified origin to a specified destination. These might be """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 stop/station IDs or coordinates based on addresses and points of interest validated by the location service or
@ -629,84 +713,64 @@ class Client():
* 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: real_time_mode = None if real_time_mode is None else real_time_mode.code
real_time_mode = None
else:
real_time_mode = real_time_mode.code
trips = [] trips = []
trips_raw = raw_trip_find( trips_raw = raw_trip_find(
accessId=self.access_id, accessId=self.access_id,
lang=lang.code, lang=lang.code,
originId=origin_id, originId=origin_id,
originExtId=origin_id_ext, originExtId=origin_id_ext,
originCoordLat=origin_coord_lat, originCoordLat=origin_coord_lat,
originCoordLong=origin_coord_lon, originCoordLong=origin_coord_lon,
originCoordName=origin_coord_name, originCoordName=origin_coord_name,
destId=destination_id, destId=destination_id,
destExtId=destination_id_ext, destExtId=destination_id_ext,
destCoordLat=destination_coord_lat, destCoordLat=destination_coord_lat,
destCoordLong=destination_coord_lon, destCoordLong=destination_coord_lon,
destCoordName=destination_coord_name, destCoordName=destination_coord_name,
via=via, via=via,
viaId=via_id, viaId=via_id,
viaGis=via_gis, viaGis=via_gis,
viaWaitTime=via_wait_time, viaWaitTime=via_wait_time,
avoid=avoid, avoid=avoid,
avoidId=avoid_id, avoidId=avoid_id,
changeTimePercent=change_time_percent, changeTimePercent=change_time_percent,
minChangeTime=change_time_min, minChangeTime=change_time_min,
maxChangeTime=change_time_max, maxChangeTime=change_time_max,
addChangeTime=change_time_add, addChangeTime=change_time_add,
maxChange=change_max, maxChange=change_max,
date=date, date=date,
time=time, time=time,
searchForArrival=search_arrival, searchForArrival=search_arrival,
numF=trips_after_time, numF=trips_after_time,
numB=trips_before_time, numB=trips_before_time,
context=context, context=context,
passlist=passlist, passlist=passlist,
operators=operators, operators=operators,
lines=lines, lines=lines,
lineids=lineids, lineids=lineids,
includeIv=iv_include, includeIv=iv_include,
ivOnly=iv_only, ivOnly=iv_only,
bikeCarriage=bike_carriage, bikeCarriage=bike_carriage,
showPassingPoints=passing_points, showPassingPoints=passing_points,
rtMode=real_time_mode, # type: ignore rtMode=real_time_mode, # type: ignore
includeEarlier=include_earlier, includeEarlier=include_earlier,
withICTAlternatives=ict_alternatives, withICTAlternatives=ict_alternatives,
tariff=tariff, tariff=tariff,
trafficMessages=messages, trafficMessages=messages,
withFreq=frequency withFreq=frequency,
) )
find_exception(trips_raw) find_exception(trips_raw)
if "Trip" in trips_raw: if "Trip" in trips_raw:
for trip in trips_raw["Trip"]: trips.extend(Trip(trip) for trip in trips_raw["Trip"])
trips.append(Trip(trip))
return trips return trips
def trip_recon(self, def trip_recon(
self,
context: Union[str, Trip], context: Union[str, Trip],
date: Union[str, datetime, None] = None, date: Union[str, datetime, None] = None,
match_real_time: Union[bool, None] = None, match_real_time: Union[bool, None] = None,
@ -717,9 +781,18 @@ class Client():
departure_dev_upper: Union[int, None] = None, departure_dev_upper: Union[int, None] = None,
passlist: bool = False, passlist: bool = False,
passing_points: bool = False, passing_points: bool = False,
real_time_mode: Union[Literal[RealTimeMode.FULL, RealTimeMode.INFOS, RealTimeMode.OFF, RealTimeMode.REALTIME, RealTimeMode.SERVER_DEFAULT], None] = None, real_time_mode: Union[
Literal[
RealTimeMode.FULL,
RealTimeMode.INFOS,
RealTimeMode.OFF,
RealTimeMode.REALTIME,
RealTimeMode.SERVER_DEFAULT,
],
None,
] = None,
tariff: Union[bool, None] = None, tariff: Union[bool, None] = 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
`ctx_recon` attribute of `Trip` object. The result will be a true copy of the original trip search result given `ctx_recon` attribute of `Trip` object. The result will be a true copy of the original trip search result given
@ -775,7 +848,6 @@ class Client():
find_exception(trips_raw) find_exception(trips_raw)
if "Trip" in trips_raw: if "Trip" in trips_raw:
for trip in trips_raw["Trip"]: trips.extend(Trip(trip) for trip in trips_raw["Trip"])
trips.append(Trip(trip))
return trips return trips

View File

@ -1,10 +1,12 @@
from typing import Any, Mapping
from isodate import parse_duration from isodate import parse_duration
class Gis():
class Gis:
"""Gis object.""" """Gis object."""
def __init__(self, ref: str, route: dict): def __init__(self, ref: str, route: Mapping[str, Any]):
self.ref = ref self.ref = ref
self.dist = route["dist"] self.dist = route["dist"]
self.duration = parse_duration(route["durS"]) self.duration = parse_duration(route["durS"])

View File

@ -1,22 +1,22 @@
from pyrmv.classes.Stop import Stop from typing import Any, Mapping
from pyrmv.classes.Message import Message
class Journey(): from pyrmv.classes.Message import Message
from pyrmv.classes.Stop import Stop
class Journey:
"""Journey object.""" """Journey object."""
def __init__(self, data: dict): def __init__(self, data: Mapping[str, Any]):
self.stops = [] self.stops = []
self.ref = data["ref"] self.ref = data["ref"]
self.direction = data["Directions"]["Direction"][0]["value"] self.direction = data["Directions"]["Direction"][0]["value"]
self.direction_flag = data["Directions"]["Direction"][0]["flag"] self.direction_flag = data["Directions"]["Direction"][0]["flag"]
self.stops.extend(Stop(stop) for stop in data["Stops"]["Stop"])
self.messages = [] self.messages = []
self.stops.extend(Stop(stop) for stop in data["Stops"]["Stop"])
if "Messages" in data: if "Messages" in data:
self.messages.extend( self.messages.extend(Message(message) for message in data["Messages"]["Message"])
Message(message) for message in data["Messages"]["Message"]
)
def __str__(self) -> str: def __str__(self) -> str:
return f"Journey with total of {len(self.stops)} stops and {len(self.messages)} messages heading {self.direction} ({self.direction_flag})" return f"Journey with total of {len(self.stops)} stops and {len(self.messages)} messages heading {self.direction} ({self.direction_flag})"

View File

@ -1,43 +1,29 @@
from typing import Any, Mapping
from isodate import parse_duration
from pyrmv.classes.Gis import Gis from pyrmv.classes.Gis import Gis
from pyrmv.classes.Message import Message from pyrmv.classes.Message import Message
from pyrmv.classes.Stop import StopTrip from pyrmv.classes.Stop import StopTrip
from isodate import parse_duration
class Leg():
class Leg:
"""Trip leg object.""" """Trip leg object."""
def __init__(self, data: dict): def __init__(self, data: Mapping[str, Any]):
self.origin = StopTrip(data["Origin"]) self.origin = StopTrip(data["Origin"])
self.destination = StopTrip(data["Destination"]) self.destination = StopTrip(data["Destination"])
self.gis = (
if "GisRef" in data: None if "GisRef" not in data else Gis(data["GisRef"]["ref"], data["GisRoute"])
self.gis = Gis(data["GisRef"]["ref"], data["GisRoute"]) )
else: self.messages = []
self.gis = None
self.index = data["idx"] self.index = data["idx"]
self.name = data["name"] self.name = data["name"]
self.type = data["type"] self.type = data["type"]
self.direction = data.get("direction")
if "direction" in data: self.number = data.get("number")
self.direction = data["direction"]
else:
self.direction = None
self.messages = []
if "Messages" in data:
for message in data["Messages"]["Message"]:
self.messages.append(Message(message))
if "number" in data:
self.number = data["number"]
else:
self.number = None
self.duration = parse_duration(data["duration"]) self.duration = parse_duration(data["duration"])
self.distance = data.get("dist")
if "dist" in data: if "Messages" in data:
self.distance = data["dist"] self.messages.extend(Message(message) for message in data["Messages"]["Message"])
else:
self.distance = None

View File

@ -1,25 +1,29 @@
from pyrmv.classes.Stop import Stop
from datetime import datetime from datetime import datetime
from typing import Any, Mapping
from isodate import parse_duration from isodate import parse_duration
class Url(): from pyrmv.classes.Stop import Stop
class Url:
"""Traffic message channel url object.""" """Traffic message channel url object."""
def __init__(self, data: dict) -> None: def __init__(self, data: Mapping[str, Any]) -> None:
self.name = data["name"] self.name = data["name"]
self.url = data["url"] self.url = data["url"]
def __str__(self) -> str: def __str__(self) -> str:
return f"{self.name}: {self.url}" return f"{self.name}: {self.url}"
class Channel():
class Channel:
"""Traffic message channel object.""" """Traffic message channel object."""
def __init__(self, data: dict) -> None: def __init__(self, data: Mapping[str, Any]) -> None:
self.name = data["name"] self.name = data["name"]
url = [] url = []
for link in url: url.extend(Url(link) for link in url)
url.append(Url(link))
self.url = url self.url = url
self.time_start = datetime.strptime(data["validFromTime"], "%H:%M:%S") self.time_start = datetime.strptime(data["validFromTime"], "%H:%M:%S")
self.date_start = datetime.strptime(data["validFromDate"], "%Y-%m-%d") self.date_start = datetime.strptime(data["validFromDate"], "%Y-%m-%d")
@ -30,30 +34,17 @@ class Channel():
return f"{self.name}: from {self.time_start} {self.date_start} until {self.time_end} {self.date_end}" return f"{self.name}: from {self.time_start} {self.date_start} until {self.time_end} {self.date_end}"
class Message(): class Message:
"""Traffic message object.""" """Traffic message object."""
def __init__(self, data: dict) -> None: def __init__(self, data: Mapping[str, Any]) -> None:
self.affected_stops = [] self.affected_stops = []
if "affectedStops" in data: self.valid_from_stop = (
for stop in data["affectedStops"]["StopLocation"]: None if "validFromStop" not in data else Stop(data["validFromStop"])
self.affected_stops.append(Stop(stop)) )
self.valid_to_stop = None if "validToStop" not in data else Stop(data["validToStop"])
if "validFromStop" in data:
self.valid_from_stop = Stop(data["validFromStop"])
else:
self.valid_from_stop = None
if "validToStop" in data:
self.valid_to_stop = Stop(data["validToStop"])
else:
self.valid_to_stop = None
self.channels = [] self.channels = []
for channel in data["channel"]: self.channels.extend(Channel(channel) for channel in data["channel"])
self.channels.append(Channel(channel))
self.id = data["id"] self.id = data["id"]
self.active = data["act"] self.active = data["act"]
self.head = data["head"] self.head = data["head"]
@ -74,11 +65,12 @@ class Message():
self.date_modified = datetime.strptime(data["modDate"], "%Y-%m-%d") self.date_modified = datetime.strptime(data["modDate"], "%Y-%m-%d")
self.daily_start = datetime.strptime(data["dailyStartingAt"], "%H:%M:%S") self.daily_start = datetime.strptime(data["dailyStartingAt"], "%H:%M:%S")
self.daily_duration = parse_duration(data["dailyDuration"]) self.daily_duration = parse_duration(data["dailyDuration"])
self.base_type = data["baseType"] if "baseType" in data else None
if "baseType" in data: if "affectedStops" in data:
self.base_type = data["baseType"] self.affected_stops.extend(
else: Stop(stop) for stop in data["affectedStops"]["StopLocation"]
self.base_type = None )
def __str__(self) -> str: def __str__(self) -> str:
return f"{self.base_type} message with priority {self.products} valid from {self.time_start.time()} {self.date_start.date()} until {self.time_end.time()} {self.date_end.date()}: {self.head} - {self.lead}" return f"{self.base_type} message with priority {self.products} valid from {self.time_start.time()} {self.date_start.date()} until {self.time_end.time()} {self.date_end.date()}: {self.head} - {self.lead}"

View File

@ -1,50 +1,28 @@
from datetime import datetime from datetime import datetime
class Stop(): class Stop:
"""Stop object.""" """Stop object."""
def __init__(self, data: dict): def __init__(self, data: dict):
self.name = data["name"] self.name = data["name"]
self.id = data["id"] self.id = data["id"]
self.ext_id = data.get("extId")
if "extId" in data: self.description = data.get("description")
self.ext_id = data["extId"]
else:
self.ext_id = None
if "description" in data:
self.description = data["description"]
else:
self.description = None
self.lon = data["lon"] self.lon = data["lon"]
self.lat = data["lat"] self.lat = data["lat"]
self.route_index = data.get("routeIdx")
if "routeIdx" in data: self.track_arrival = data.get("arrTrack")
self.route_index = data["routeIdx"] self.track_departure = data.get("depTrack")
else:
self.route_index = None
if "arrTrack" in data:
self.track_arrival = data["arrTrack"]
else:
self.track_arrival = None
if "depTrack" in data:
self.track_departure = data["depTrack"]
else:
self.track_departure = None
def __str__(self) -> str: def __str__(self) -> str:
return f"Stop {self.name} at {self.lon}, {self.lat}" return f"Stop {self.name} at {self.lon}, {self.lat}"
class StopTrip(Stop): class StopTrip(Stop):
"""Trip stop object. It's like a Stop object, but with a date and time.""" """Trip stop object. It's like a Stop object, but with a date and time."""
def __init__(self, data: dict): def __init__(self, data: dict):
self.type = data["type"] self.type = data["type"]
self.date = datetime.strptime(data["date"], "%Y-%m-%d") self.date = datetime.strptime(data["date"], "%Y-%m-%d")
self.time = datetime.strptime(data["time"], "%H:%M:%S") self.time = datetime.strptime(data["time"], "%H:%M:%S")

View File

@ -1,37 +1,28 @@
from pyrmv.classes.Leg import Leg
from pyrmv.classes.Stop import StopTrip
from isodate import parse_duration from isodate import parse_duration
class Trip(): from pyrmv.classes.Leg import Leg
from pyrmv.classes.Stop import StopTrip
class Trip:
"""Trip object.""" """Trip object."""
def __init__(self, data: dict): def __init__(self, data: dict):
self.raw_data = data self.raw_data = data
self.origin = StopTrip(data["Origin"]) self.origin = StopTrip(data["Origin"])
self.destination = StopTrip(data["Destination"]) self.destination = StopTrip(data["Destination"])
self.legs = [] self.legs = []
for leg in data["LegList"]["Leg"]: self.legs.extend(Leg(leg) for leg in data["LegList"]["Leg"])
self.legs.append(Leg(leg))
self.calculation = data["calculation"] self.calculation = data["calculation"]
self.index = data["idx"] self.index = data["idx"]
self.id = data["tripId"] self.id = data["tripId"]
self.ctx_recon = data["ctxRecon"] self.ctx_recon = data["ctxRecon"]
self.duration = parse_duration(data["duration"]) self.duration = parse_duration(data["duration"])
self.real_time_duration = (
if "rtDuration" in data: None if "rtDuration" not in data else parse_duration(data["rtDuration"])
self.real_time_duration = parse_duration(data["rtDuration"]) )
else:
self.real_time_duration = None
self.checksum = data["checksum"] self.checksum = data["checksum"]
self.transfer_count = data.get("transferCount", 0)
if "transferCount" in data:
self.transfer_count = data["transferCount"]
else:
self.transfer_count = 0
def __str__(self) -> str: def __str__(self) -> str:
return f"Trip from {self.origin.name} to {self.destination.name} lasting {self.duration} ({self.real_time_duration}) with {len(self.legs)} legs and {self.transfer_count} transfers" return f"Trip from {self.origin.name} to {self.destination.name} lasting {self.duration} ({self.real_time_duration}) with {len(self.legs)} legs and {self.transfer_count} transfers"

View File

@ -1,9 +1,9 @@
from .Board import BoardArrival, BoardDeparture, LineArrival, LineDeparture from .Board import BoardArrival, BoardDeparture, LineArrival, LineDeparture
from .Client import Client
from .Gis import Gis from .Gis import Gis
from .Journey import Journey from .Journey import Journey
from .Leg import Leg from .Leg import Leg
from .Message import Message, Channel, Url from .Message import Channel, Message, Url
from .Stop import Stop, StopTrip from .Stop import Stop, StopTrip
from .Ticket import Ticket from .Ticket import Ticket
from .Trip import Trip from .Trip import Trip
from .Client import Client

View File

@ -0,0 +1 @@
from .product import PRODUCTS

View File

@ -1,10 +1,10 @@
from .product import Product
from .rt_mode import RealTimeMode
from .lang import Language
from .location_type import LocationType
from .selection_mode import SelectionMode
from .search_mode import SearchMode
from .filter_mode import FilterMode
from .board_type import BoardArrivalType, BoardDepartureType
from .aff_journey_mode import AffectedJourneyMode from .aff_journey_mode import AffectedJourneyMode
from .aff_journey_stop_mode import AffectedJourneyStopMode from .aff_journey_stop_mode import AffectedJourneyStopMode
from .board_type import BoardArrivalType, BoardDepartureType
from .filter_mode import FilterMode
from .lang import Language
from .location_type import LocationType
from .product import Product
from .rt_mode import RealTimeMode
from .search_mode import SearchMode
from .selection_mode import SelectionMode

View File

@ -1,6 +1,8 @@
from enum import auto from enum import auto
from .auto_name import AutoName from .auto_name import AutoName
class AffectedJourneyMode(AutoName): class AffectedJourneyMode(AutoName):
"""Enumeration used to declare types of HIM search modes.""" """Enumeration used to declare types of HIM search modes."""

View File

@ -1,6 +1,8 @@
from enum import auto from enum import auto
from .auto_name import AutoName from .auto_name import AutoName
class AffectedJourneyStopMode(AutoName): class AffectedJourneyStopMode(AutoName):
"""Enumeration used to declare types of affected journey stops return modes.""" """Enumeration used to declare types of affected journey stops return modes."""

View File

@ -2,7 +2,9 @@
# https://github.com/pyrogram/pyrogram/blob/master/pyrogram/enums/auto_name.py # https://github.com/pyrogram/pyrogram/blob/master/pyrogram/enums/auto_name.py
from enum import Enum from enum import Enum
from pyrmv.const.product import PRODUCTS
from pyrmv.const import PRODUCTS
class AutoName(Enum): class AutoName(Enum):
def __init__(self, code) -> None: def __init__(self, code) -> None:
@ -14,6 +16,7 @@ class AutoName(Enum):
def __repr__(self): def __repr__(self):
return f"pyrmv.enums.{self}" return f"pyrmv.enums.{self}"
class AutoNameProduct(AutoName): class AutoNameProduct(AutoName):
def __init__(self, code) -> None: def __init__(self, code) -> None:
self.code = PRODUCTS[code] self.code = PRODUCTS[code]

View File

@ -1,6 +1,8 @@
from enum import auto from enum import auto
from .auto_name import AutoName from .auto_name import AutoName
class BoardArrivalType(AutoName): class BoardArrivalType(AutoName):
"""Enumeration used to declare types of arrival board. """Enumeration used to declare types of arrival board.
@ -22,6 +24,7 @@ class BoardArrivalType(AutoName):
ARR_STATION = auto() ARR_STATION = auto()
"Arrival board with all journeys at any masts of the requested station" "Arrival board with all journeys at any masts of the requested station"
class BoardDepartureType(AutoName): class BoardDepartureType(AutoName):
"""Enumeration used to declare types of departure board. """Enumeration used to declare types of departure board.

View File

@ -1,6 +1,8 @@
from enum import auto from enum import auto
from .auto_name import AutoName from .auto_name import AutoName
class FilterMode(AutoName): class FilterMode(AutoName):
"""Enumeration used to declare filters for nearby searches. """Enumeration used to declare filters for nearby searches.

View File

@ -1,24 +1,44 @@
from enum import auto from enum import auto
from .auto_name import AutoName from .auto_name import AutoName
class Language(AutoName): class Language(AutoName):
"""Enumeration used to declare locales as ISO-3166 codes (but only available in HAFAS ones).""" """Enumeration used to declare locales as ISO-3166 codes (but only available in HAFAS ones)."""
DE = auto() AR = auto()
"German" "Arabic"
CA = auto()
"Catalan, Valencian"
DA = auto() DA = auto()
"Danish" "Danish"
DE = auto()
"German"
EL = auto()
"Greek"
EN = auto() EN = auto()
"English" "English"
ES = auto() ES = auto()
"Spanish" "Spanish"
FI = auto()
"Finnish"
FR = auto() FR = auto()
"French" "French"
HI = auto()
"Hindi"
HR = auto()
"Croatian"
HU = auto() HU = auto()
"Hungarian" "Hungarian"
@ -34,8 +54,26 @@ class Language(AutoName):
PL = auto() PL = auto()
"Polish" "Polish"
RU = auto()
"Russian"
SK = auto()
"Slovak"
SL = auto()
"Slovenian"
SV = auto() SV = auto()
"Swedish" "Swedish"
TL = auto()
"Tagalog"
TR = auto() TR = auto()
"Turkish" "Turkish"
UR = auto()
"Urdu"
ZH = auto()
"Chinese"

View File

@ -1,6 +1,8 @@
from enum import auto from enum import auto
from .auto_name import AutoName from .auto_name import AutoName
class LocationType(AutoName): class LocationType(AutoName):
"""Enumeration used to declare types of location filter. """Enumeration used to declare types of location filter.

View File

@ -1,6 +1,8 @@
from enum import auto from enum import auto
from .auto_name import AutoNameProduct from .auto_name import AutoNameProduct
class Product(AutoNameProduct): class Product(AutoNameProduct):
"""Enumeration used to declare types of transport.""" """Enumeration used to declare types of transport."""
@ -11,7 +13,7 @@ class Product(AutoNameProduct):
"InterCity (commonly abbreviated IC on timetables and tickets) is the classification applied to certain long-distance passenger train services in Europe. Such trains (in contrast to regional, local, or commuter trains) generally call at major stations only." "InterCity (commonly abbreviated IC on timetables and tickets) is the classification applied to certain long-distance passenger train services in Europe. Such trains (in contrast to regional, local, or commuter trains) generally call at major stations only."
EC = auto() EC = auto()
"EuroCity, abbreviated as EC, is a cross-border train category within the European inter-city rail network. In contrast to trains allocated to the lower-level \"IC\" (InterCity) category, EC trains are international services that meet 20 criteria covering comfort, speed, food service, and cleanliness." 'EuroCity, abbreviated as EC, is a cross-border train category within the European inter-city rail network. In contrast to trains allocated to the lower-level "IC" (InterCity) category, EC trains are international services that meet 20 criteria covering comfort, speed, food service, and cleanliness.'
R = auto() R = auto()
"Regional rail, also known as local trains and stopping trains, are passenger rail services that operate between towns and cities. These trains operate with more stops over shorter distances than inter-city rail, but fewer stops and faster service than commuter rail." "Regional rail, also known as local trains and stopping trains, are passenger rail services that operate between towns and cities. These trains operate with more stops over shorter distances than inter-city rail, but fewer stops and faster service than commuter rail."

View File

@ -1,6 +1,8 @@
from enum import auto from enum import auto
from .auto_name import AutoName from .auto_name import AutoName
class RealTimeMode(AutoName): class RealTimeMode(AutoName):
"""Enumeration used to declare types of real-time traffic.""" """Enumeration used to declare types of real-time traffic."""

View File

@ -1,6 +1,8 @@
from enum import auto from enum import auto
from .auto_name import AutoName from .auto_name import AutoName
class SearchMode(AutoName): class SearchMode(AutoName):
"""Enumeration used to declare types of HIM search modes.""" """Enumeration used to declare types of HIM search modes."""

View File

@ -1,6 +1,8 @@
from enum import auto from enum import auto
from .auto_name import AutoName from .auto_name import AutoName
class SelectionMode(AutoName): class SelectionMode(AutoName):
"""Enumeration used to declare location selection modes. """Enumeration used to declare location selection modes.

View File

@ -0,0 +1,7 @@
from .api_errors import *
from .int_errors import *
from .not_ready import *
from .ps_errors import *
from .sot_errors import *
from .svc_errors import *
from .unknown_error import *

View File

@ -2,32 +2,38 @@ class ApiAuthError(Exception):
""" """
Access denied for accessId provided. Access denied for accessId provided.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__
class ApiQuotaError(Exception): class ApiQuotaError(Exception):
""" """
Quota exceeded for accessId provided. Quota exceeded for accessId provided.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__
class ApiTooManyRequests(Exception): class ApiTooManyRequests(Exception):
""" """
Too many requests. Too many requests.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__
class ApiParamError(Exception): class ApiParamError(Exception):
"""Exception raised for errors in the input arguments. """Exception raised for errors in the input arguments.
@ -42,12 +48,14 @@ class ApiParamError(Exception):
super().__init__(self.errorText) super().__init__(self.errorText)
def __str__(self): def __str__(self):
return f'{self.errorCode} -> {self.errorText}' return f"{self.errorCode} -> {self.errorText}"
class ApiFormatError(Exception): class ApiFormatError(Exception):
""" """
Response format not supported. Response format not supported.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)

View File

@ -2,26 +2,31 @@ class IntError(Exception):
""" """
Internal RMV server error. Internal RMV server error.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__
class IntGatewayError(Exception): class IntGatewayError(Exception):
""" """
Communication error with RMV backend systems. Communication error with RMV backend systems.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__
class IntTimeoutError(Exception): class IntTimeoutError(Exception):
""" """
Timeout during service processing. Timeout during service processing.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)

View File

@ -2,6 +2,7 @@ class NotReadyYetError(Exception):
""" """
This method is not finished yet. This method is not finished yet.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)

View File

@ -6,6 +6,7 @@ class PsIncorrectParamError(Exception):
forward/backward from the end/beginning of the forward/backward from the end/beginning of the
connection. connection.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)

View File

@ -2,46 +2,55 @@ class SotAlreadyArrivedError(Exception):
""" """
Trip already arrived. Trip already arrived.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__
class SotNotStartedError(Exception): class SotNotStartedError(Exception):
""" """
Trip not started. Trip not started.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__
class SotCancelledError(Exception): class SotCancelledError(Exception):
""" """
Trip cancelled. Trip cancelled.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__
class SotAllTrainsFilteredError(Exception): class SotAllTrainsFilteredError(Exception):
""" """
All trips filtered. All trips filtered.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__
class SotStayOnTripError(Exception): class SotStayOnTripError(Exception):
""" """
No change. Stay on trip. No change. Stay on trip.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)

View File

@ -12,132 +12,158 @@ class SvcParamError(Exception):
super().__init__(self.errorText) super().__init__(self.errorText)
def __str__(self): def __str__(self):
return f'{self.errorCode} -> {self.errorText}' return f"{self.errorCode} -> {self.errorText}"
class SvcLocationError(Exception): class SvcLocationError(Exception):
""" """
Location missing or invalid. Location missing or invalid.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__
class SvcLocationArrivalError(Exception): class SvcLocationArrivalError(Exception):
""" """
Arrival location missing or invalid. Arrival location missing or invalid.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__
class SvcLocationDepartureError(Exception): class SvcLocationDepartureError(Exception):
""" """
Departure location missing or invalid. Departure location missing or invalid.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__
class SvcLocationViaError(Exception): class SvcLocationViaError(Exception):
""" """
Unknown change stop. Unknown change stop.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__
class SvcLocationEqualError(Exception): class SvcLocationEqualError(Exception):
""" """
Origin/destination or vias are equal. Origin/destination or vias are equal.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__
class SvcLocationNearError(Exception): class SvcLocationNearError(Exception):
""" """
Origin and destination are too close. Origin and destination are too close.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__
class SvcDatetimeError(Exception): class SvcDatetimeError(Exception):
""" """
Date/time are missing or invalid. Date/time are missing or invalid.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__
class SvcDatetimePeriodError(Exception): class SvcDatetimePeriodError(Exception):
""" """
Date/time are not in timetable or allowed period. Date/time are not in timetable or allowed period.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__
class SvcProductError(Exception): class SvcProductError(Exception):
""" """
Product field missing or invalid. Product field missing or invalid.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__
class SvcContextError(Exception): class SvcContextError(Exception):
""" """
Context is invalid. Context is invalid.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__
class SvcNoResultError(Exception): class SvcNoResultError(Exception):
""" """
No result found. No result found.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__
class SvcSearchError(Exception): class SvcSearchError(Exception):
""" """
Unsuccessful search. Unsuccessful search.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)
def __str__(self): def __str__(self):
return self.__doc__ return self.__doc__
class SvcNoMatchError(Exception): class SvcNoMatchError(Exception):
""" """
No match found. No match found.
""" """
def __init__(self): def __init__(self):
super().__init__(self.__doc__) super().__init__(self.__doc__)

View File

@ -12,4 +12,4 @@ class UnknownError(Exception):
super().__init__(self.errorText) super().__init__(self.errorText)
def __str__(self): def __str__(self):
return f'{self.errorCode} -> {self.errorText}' return f"{self.errorCode} -> {self.errorText}"

View File

@ -1,6 +1,7 @@
from requests import get
from datetime import datetime, timedelta from datetime import datetime, timedelta
from typing import Union from typing import Union
from requests import get
from xmltodict import parse as xmlparse from xmltodict import parse as xmlparse
try: try:
@ -8,8 +9,10 @@ try:
except ImportError: except ImportError:
from typing_extensions import Literal from typing_extensions import Literal
# 2.25. Arrival Board (arrivalBoard) # 2.25. Arrival Board (arrivalBoard)
def board_arrival(accessId: str, def board_arrival(
accessId: str,
json: bool = True, json: bool = True,
id: Union[str, None] = None, id: Union[str, None] = None,
extId: Union[str, None] = None, extId: Union[str, None] = None,
@ -25,8 +28,8 @@ def board_arrival(accessId: str,
attributes: Union[str, list, None] = None, attributes: Union[str, list, None] = None,
platforms: Union[str, list, None] = None, platforms: Union[str, list, None] = None,
passlist: bool = False, passlist: bool = False,
boardType: Literal["ARR", "ARR_EQUIVS", "ARR_MAST", "ARR_STATION"] = "ARR" boardType: Literal["ARR", "ARR_EQUIVS", "ARR_MAST", "ARR_STATION"] = "ARR",
) -> dict: ) -> dict:
"""The arrival board can be retrieved by a call to the arrivalBoard service. This method will return the next """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.
@ -58,12 +61,8 @@ def board_arrival(accessId: str,
* dict: Output from RMV. Dict will contain "errorCode" and "errorText" if exception occurs. * 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 = {} payload = {}
headers = {"Accept": "application/json"} if json else {"Accept": "application/xml"}
for var, val in locals().items(): for var, val in locals().items():
if str(var) == "date": if str(var) == "date":
@ -74,16 +73,12 @@ def board_arrival(accessId: str,
payload[str(var)] = val payload[str(var)] = val
elif str(var) == "time": elif str(var) == "time":
if val != None: if val != None:
if isinstance(val, datetime): payload[str(var)] = (
payload[str(var)] = val.strftime("%H:%M") val.strftime("%H:%M") if isinstance(val, datetime) else val
else: )
payload[str(var)] = val
elif str(var) == "duration": elif str(var) == "duration":
if val != None: if val != None:
if isinstance(val, timedelta): payload[str(var)] = val.minutes if isinstance(val, timedelta) else val
payload[str(var)] = val.minutes # type: ignore
else:
payload[str(var)] = val
elif str(var) == "boardType": elif str(var) == "boardType":
if val != None: if val != None:
payload["type"] = val.upper() 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) output = get("https://www.rmv.de/hapi/arrivalBoard", params=payload, headers=headers)
if json: return output.json() if json else xmlparse(output.content)
return output.json()
else:
return xmlparse(output.content)

View File

@ -1,6 +1,7 @@
from requests import get
from datetime import datetime, timedelta from datetime import datetime, timedelta
from typing import Union from typing import Union
from requests import get
from xmltodict import parse as xmlparse from xmltodict import parse as xmlparse
try: try:
@ -8,8 +9,10 @@ try:
except ImportError: except ImportError:
from typing_extensions import Literal from typing_extensions import Literal
# 2.24. Departure Board (departureBoard) # 2.24. Departure Board (departureBoard)
def board_departure(accessId: str, def board_departure(
accessId: str,
json: bool = True, json: bool = True,
id: Union[str, None] = None, id: Union[str, None] = None,
extId: Union[str, None] = None, extId: Union[str, None] = None,
@ -25,8 +28,8 @@ def board_departure(accessId: str,
attributes: Union[str, list, None] = None, attributes: Union[str, list, None] = None,
platforms: Union[str, list, None] = None, platforms: Union[str, list, None] = None,
passlist: bool = False, passlist: bool = False,
boardType: Literal["DEP", "DEP_EQUIVS", "DEP_MAST", "DEP_STATION"] = "DEP" boardType: Literal["DEP", "DEP_EQUIVS", "DEP_MAST", "DEP_STATION"] = "DEP",
) -> dict: ) -> dict:
"""The separture board can be retrieved by a call to the departureBoard service. This method will return the """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 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.
@ -59,12 +62,8 @@ def board_departure(accessId: str,
* dict: Output from RMV. Dict will contain "errorCode" and "errorText" if exception occurs. * 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 = {} payload = {}
headers = {"Accept": "application/json"} if json else {"Accept": "application/xml"}
for var, val in locals().items(): for var, val in locals().items():
if str(var) == "date": if str(var) == "date":
@ -75,16 +74,12 @@ def board_departure(accessId: str,
payload[str(var)] = val payload[str(var)] = val
elif str(var) == "time": elif str(var) == "time":
if val != None: if val != None:
if isinstance(val, datetime): payload[str(var)] = (
payload[str(var)] = val.strftime("%H:%M") val.strftime("%H:%M") if isinstance(val, datetime) else val
else: )
payload[str(var)] = val
elif str(var) == "duration": elif str(var) == "duration":
if val != None: if val != None:
if isinstance(val, timedelta): payload[str(var)] = val.minutes if isinstance(val, timedelta) else val
payload[str(var)] = val.minutes # type: ignore
else:
payload[str(var)] = val
elif str(var) == "boardType": elif str(var) == "boardType":
if val != None: if val != None:
payload["type"] = val.upper() 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) output = get("https://www.rmv.de/hapi/departureBoard", params=payload, headers=headers)
if json: return output.json() if json else xmlparse(output.content)
return output.json()
else:
return xmlparse(output.content)

View File

@ -1,17 +1,20 @@
from requests import get
from typing import OrderedDict, Union
from xmltodict import parse as xmlparse
from datetime import datetime 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: try:
from typing import Literal from typing import Literal
except ImportError: except ImportError:
from typing_extensions import Literal from typing_extensions import Literal
# 2.37. HIM Search (himsearch) # 2.37. HIM Search (himsearch)
def him_search(accessId: str, def him_search(
accessId: str,
json: bool = True, json: bool = True,
dateB: Union[str, datetime, None] = None, dateB: Union[str, datetime, None] = None,
dateE: Union[str, datetime, None] = None, dateE: Union[str, datetime, None] = None,
@ -44,8 +47,8 @@ def him_search(accessId: str,
affectedJourneyStopMode: Union[Literal["ALL", "IMP", "OFF"], None] = None, affectedJourneyStopMode: Union[Literal["ALL", "IMP", "OFF"], None] = None,
orderBy: Union[str, list, None] = None, orderBy: Union[str, list, None] = None,
minprio: Union[str, int, None] = None, minprio: Union[str, int, None] = None,
maxprio: Union[str, int, None] = None maxprio: Union[str, int, None] = None,
) -> dict: ) -> dict:
"""The himSearch will return a list of HIM messages if matched by the given criteria as well as affected """The himSearch will return a list of HIM messages if matched by the given criteria as well as affected
products if any. products if any.
@ -91,26 +94,21 @@ def him_search(accessId: str,
* dict: Output from RMV. Dict will contain "errorCode" and "errorText" if exception occurs. * 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 = {} payload = {}
headers = {"Accept": "application/json"} if json else {"Accept": "application/xml"}
for var, val in locals().items(): for var, val in locals().items():
if str(var) in ["dateB", "dateE"]: if str(var) in {"dateB", "dateE"}:
if val != None: if val != None:
if isinstance(val, datetime): if isinstance(val, datetime):
payload[str(var)] = val.strftime("%Y-%m-%d") payload[str(var)] = val.strftime("%Y-%m-%d")
else: else:
payload[str(var)] = val payload[str(var)] = val
elif str(var) in ["timeB", "timeE"]: elif str(var) in {"timeB", "timeE"}:
if val != None: if val != None:
if isinstance(val, datetime): payload[str(var)] = (
payload[str(var)] = val.strftime("%H:%M") val.strftime("%H:%M") if isinstance(val, datetime) else val
else: )
payload[str(var)] = val
elif str(var) == "weekdays": elif str(var) == "weekdays":
if val != None: if val != None:
if isinstance(val, OrderedDict): 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) output = get("https://www.rmv.de/hapi/himsearch", params=payload, headers=headers)
if json: return output.json() if json else xmlparse(output.content)
return output.json()
else:
return xmlparse(output.content)

View File

@ -1,6 +1,7 @@
from datetime import datetime from datetime import datetime
from requests import get
from typing import Union from typing import Union
from requests import get
from xmltodict import parse as xmlparse from xmltodict import parse as xmlparse
try: try:
@ -8,8 +9,10 @@ try:
except ImportError: except ImportError:
from typing_extensions import Literal from typing_extensions import Literal
# 2.26. Journey Detail (journeyDetail) # 2.26. Journey Detail (journeyDetail)
def journey_detail(accessId: str, def journey_detail(
accessId: str,
id: str, id: str,
json: bool = True, json: bool = True,
date: Union[str, datetime, None] = None, date: Union[str, datetime, None] = None,
@ -21,8 +24,8 @@ def journey_detail(accessId: str,
fromIdx: Union[int, None] = None, fromIdx: Union[int, None] = None,
toId: Union[str, None] = None, toId: Union[str, None] = None,
toIdx: Union[int, None] = None, toIdx: Union[int, None] = None,
baim: bool = False baim: bool = False,
) -> dict: ) -> dict:
"""The journey_detail method will deliver information about the complete route of a vehicle. The journey """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 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 including all departure and arrival times (with real-time data if available) and additional information like
@ -49,12 +52,8 @@ def journey_detail(accessId: str,
* dict: Output from RMV. Dict will contain "errorCode" and "errorText" if exception occurs. * 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 = {} payload = {}
headers = {"Accept": "application/json"} if json else {"Accept": "application/xml"}
for var, val in locals().items(): for var, val in locals().items():
if str(var) == "rtMode": 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) output = get("https://www.rmv.de/hapi/journeyDetail", params=payload, headers=headers)
if json: return output.json() if json else xmlparse(output.content)
return output.json()
else:
return xmlparse(output.content)

View File

@ -1,5 +1,6 @@
from requests import get
from typing import Union from typing import Union
from requests import get
from xmltodict import parse as xmlparse from xmltodict import parse as xmlparse
try: try:
@ -7,11 +8,15 @@ try:
except ImportError: except ImportError:
from typing_extensions import Literal from typing_extensions import Literal
# 2.4. Location Search by Coordinate (location.nearbystops) # 2.4. Location Search by Coordinate (location.nearbystops)
def stop_by_coords(accessId: str, def stop_by_coords(
accessId: str,
originCoordLat: Union[str, float], originCoordLat: Union[str, float],
originCoordLong: Union[str, float], originCoordLong: Union[str, float],
lang: Literal["de", "da", "en", "es", "fr", "hu", "it", "nl", "no", "pl", "sv", "tr"] = "en", lang: Literal[
"de", "da", "en", "es", "fr", "hu", "it", "nl", "no", "pl", "sv", "tr"
] = "en",
json: bool = True, json: bool = True,
radius: Union[int, float] = 1000, radius: Union[int, float] = 1000,
maxNo: int = 10, maxNo: int = 10,
@ -20,8 +25,8 @@ def stop_by_coords(accessId: str,
products: Union[int, None] = None, products: Union[int, None] = None,
meta: Union[str, None] = None, meta: Union[str, None] = None,
sattributes: Union[str, list, None] = None, sattributes: Union[str, list, None] = None,
sinfotexts: Union[str, list, None] = None sinfotexts: Union[str, list, None] = None,
) -> dict: ) -> dict:
"""The location.nearbystops service returns a list of stops around a given center coordinate (within a """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. radius of 1000m). The returned results are ordered by their distance to the center coordinate.
@ -46,12 +51,8 @@ def stop_by_coords(accessId: str,
* dict: Output from RMV. Dict will contain "errorCode" and "errorText" if exception occurs. * 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 = {} payload = {}
headers = {"Accept": "application/json"} if json else {"Accept": "application/xml"}
for var, val in locals().items(): for var, val in locals().items():
if str(var) == "stopType": if str(var) == "stopType":
@ -64,9 +65,8 @@ def stop_by_coords(accessId: str,
if val != None: if val != None:
payload[str(var)] = val 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() if json else xmlparse(output.content)
return output.json()
else:
return xmlparse(output.content)

View File

@ -1,5 +1,6 @@
from requests import get
from typing import Union from typing import Union
from requests import get
from xmltodict import parse as xmlparse from xmltodict import parse as xmlparse
try: try:
@ -7,10 +8,14 @@ try:
except ImportError: except ImportError:
from typing_extensions import Literal from typing_extensions import Literal
# 2.3. Location Search by Name (location.name) # 2.3. Location Search by Name (location.name)
def stop_by_name(accessId: str, def stop_by_name(
accessId: str,
inputString: str, inputString: str,
lang: Literal["de", "da", "en", "es", "fr", "hu", "it", "nl", "no", "pl", "sv", "tr"] = "en", lang: Literal[
"de", "da", "en", "es", "fr", "hu", "it", "nl", "no", "pl", "sv", "tr"
] = "en",
json: bool = True, json: bool = True,
maxNo: int = 10, maxNo: int = 10,
stopType: Literal["A", "ALL", "AP", "P", "S", "SA", "SP"] = "ALL", stopType: Literal["A", "ALL", "AP", "P", "S", "SA", "SP"] = "ALL",
@ -23,8 +28,8 @@ def stop_by_name(accessId: str,
meta: Union[str, None] = None, meta: Union[str, None] = None,
stations: Union[str, list, None] = None, stations: Union[str, list, None] = None,
sattributes: Union[str, list, None] = None, sattributes: Union[str, list, None] = None,
filterMode: Literal["DIST_PERI", "EXCL_PERI", "SLCT_PERI"] = "DIST_PERI" filterMode: Literal["DIST_PERI", "EXCL_PERI", "SLCT_PERI"] = "DIST_PERI",
) -> dict: ) -> dict:
"""The location.name service can be used to perform a pattern matching of a user input and to retrieve a list """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 of possible matches in the journey planner database. Possible matches might be stops/stations, points of
interest and addresses. interest and addresses.
@ -57,12 +62,8 @@ def stop_by_name(accessId: str,
* dict: Output from RMV. Dict will contain "errorCode" and "errorText" if exception occurs. * 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 = {} payload = {}
headers = {"Accept": "application/json"} if json else {"Accept": "application/xml"}
for var, val in locals().items(): for var, val in locals().items():
if str(var) == "inputString": 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) output = get("https://www.rmv.de/hapi/location.name", params=payload, headers=headers)
if json: return output.json() if json else xmlparse(output.content)
return output.json()
else:
return xmlparse(output.content)

View File

@ -1,6 +1,7 @@
from datetime import datetime from datetime import datetime
from requests import get
from typing import List, Union from typing import List, Union
from requests import get
from xmltodict import parse as xmlparse from xmltodict import parse as xmlparse
try: try:
@ -8,120 +9,98 @@ try:
except ImportError: except ImportError:
from typing_extensions import Literal 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,
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, originId: Union[str, None] = None,
originExtId: Union[str, None] = None, originExtId: Union[str, None] = None,
originCoordLat: Union[str, float, None] = None, originCoordLat: Union[str, float, None] = None,
originCoordLong: Union[str, float, None] = None, originCoordLong: Union[str, float, None] = None,
originCoordName: Union[str, None] = None, originCoordName: Union[str, None] = None,
destId: Union[str, None] = None, destId: Union[str, None] = None,
destExtId: Union[str, None] = None, destExtId: Union[str, None] = None,
destCoordLat: Union[str, float, None] = None, destCoordLat: Union[str, float, None] = None,
destCoordLong: Union[str, float, None] = None, destCoordLong: Union[str, float, None] = None,
destCoordName: Union[str, None] = None, destCoordName: Union[str, None] = None,
via: Union[str, None] = None, via: Union[str, None] = None,
viaId: Union[str, None] = None, viaId: Union[str, None] = None,
viaWaitTime: int = 0, viaWaitTime: int = 0,
avoid: Union[str, None] = None, avoid: Union[str, None] = None,
avoidId: Union[str, None] = None, avoidId: Union[str, None] = None,
viaGis: Union[str, None] = None, viaGis: Union[str, None] = None,
changeTimePercent: int = 100, changeTimePercent: int = 100,
minChangeTime: Union[int, None] = None, minChangeTime: Union[int, None] = None,
maxChangeTime: Union[int, None] = None, maxChangeTime: Union[int, None] = None,
addChangeTime: Union[int, None] = None, addChangeTime: Union[int, None] = None,
maxChange: Union[int, None] = None, maxChange: Union[int, None] = None,
date: Union[str, datetime, None] = None, date: Union[str, datetime, None] = None,
time: Union[str, datetime, None] = None, time: Union[str, datetime, None] = None,
searchForArrival: bool = False, searchForArrival: bool = False,
numF: Union[int, None] = None, numF: Union[int, None] = None,
numB: Union[int, None] = None, numB: Union[int, None] = None,
context: Union[str, None] = None, context: Union[str, None] = None,
poly: bool = False, poly: bool = False,
polyEnc: Literal["DLT", "GPA", "N"] = "N", polyEnc: Literal["DLT", "GPA", "N"] = "N",
passlist: bool = False, passlist: bool = False,
products: Union[int, None] = None, products: Union[int, None] = None,
operators: Union[str, list, None] = None, operators: Union[str, list, None] = None,
attributes: Union[str, list, None] = None, attributes: Union[str, list, None] = None,
sattributes: Union[str, list, None] = None, sattributes: Union[str, list, None] = None,
fattributes: Union[str, list, None] = None, fattributes: Union[str, list, None] = None,
lines: Union[str, list, None] = None, lines: Union[str, list, None] = None,
lineids: Union[str, list, None] = None, lineids: Union[str, list, None] = None,
avoidPaths: Union[List[Literal["SW", "EA", "ES", "RA", "CB"]], None] = None, avoidPaths: Union[List[Literal["SW", "EA", "ES", "RA", "CB"]], None] = None,
originWalk: Union[str, list, None] = None, originWalk: Union[str, list, None] = None,
originBike: Union[str, list, None] = None, originBike: Union[str, list, None] = None,
originCar: Union[str, list, None] = None, originCar: Union[str, list, None] = None,
originTaxi: Union[str, list, None] = None, originTaxi: Union[str, list, None] = None,
originPark: Union[str, list, None] = None, originPark: Union[str, list, None] = None,
originMeta: Union[str, list, None] = None, originMeta: Union[str, list, None] = None,
destWalk: Union[str, list, None] = None, destWalk: Union[str, list, None] = None,
destBike: Union[str, list, None] = None, destBike: Union[str, list, None] = None,
destCar: Union[str, list, None] = None, destCar: Union[str, list, None] = None,
destTaxi: Union[str, list, None] = None, destTaxi: Union[str, list, None] = None,
destPark: Union[str, list, None] = None, destPark: Union[str, list, None] = None,
destMeta: Union[str, list, None] = None, destMeta: Union[str, list, None] = None,
totalWalk: Union[str, list, None] = None, totalWalk: Union[str, list, None] = None,
totalBike: Union[str, list, None] = None, totalBike: Union[str, list, None] = None,
totalCar: Union[str, list, None] = None, totalCar: Union[str, list, None] = None,
totalTaxi: Union[str, list, None] = None, totalTaxi: Union[str, list, None] = None,
totalMeta: Union[str, list, None] = None, totalMeta: Union[str, list, None] = None,
gisProducts: Union[str, None] = None, gisProducts: Union[str, None] = None,
includeIv: bool = False, includeIv: bool = False,
ivOnly: bool = False, ivOnly: bool = False,
mobilityProfile: Union[str, None] = None, mobilityProfile: Union[str, None] = None,
bikeCarriage: bool = False, bikeCarriage: bool = False,
bikeCarriageType: Union[Literal["SINGLEBIKES", "SMALLGROUPS", "LARGEGROUPS"], None] = None, bikeCarriageType: Union[
Literal["SINGLEBIKES", "SMALLGROUPS", "LARGEGROUPS"], None
] = None,
sleepingCar: bool = False, sleepingCar: bool = False,
couchetteCoach: bool = False, couchetteCoach: bool = False,
showPassingPoints: bool = False, showPassingPoints: bool = False,
baim: bool = False, baim: bool = False,
eco: bool = False, eco: bool = False,
ecoCmp: bool = False, ecoCmp: bool = False,
ecoParams: Union[str, None] = None, ecoParams: Union[str, None] = None,
rtMode: Union[Literal["FULL", "INFOS", "OFF", "REALTIME", "SERVER_DEFAULT"], None] = None, rtMode: Union[Literal["FULL", "INFOS", "OFF", "REALTIME", "SERVER_DEFAULT"], None] = None,
unsharp: bool = False, unsharp: bool = False,
trainFilter: Union[str, None] = None, trainFilter: Union[str, None] = None,
economic: bool = False, economic: bool = False,
groupFilter: Union[str, None] = None, groupFilter: Union[str, None] = None,
blockingList: Union[str, None] = None, blockingList: Union[str, None] = None,
blockedEdges: Union[str, None] = None, blockedEdges: Union[str, None] = None,
trainComposition: bool = False, trainComposition: bool = False,
includeEarlier: bool = False, includeEarlier: bool = False,
withICTAlternatives: bool = False, withICTAlternatives: bool = False,
tariff: Union[bool, None] = None, tariff: Union[bool, None] = None,
trafficMessages: bool = False, trafficMessages: bool = False,
travellerProfileData: Union[str, None] = None, travellerProfileData: Union[str, None] = None,
withFreq: bool = True withFreq: bool = True,
) -> dict: ) -> dict:
"""The trip service calculates a trip from a specified origin to a specified destination. These might be """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 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.
@ -219,12 +198,8 @@ def trip_find(accessId: str,
* dict: Output from RMV. Dict will contain "errorCode" and "errorText" if exception occurs. * 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 = {} payload = {}
headers = {"Accept": "application/json"} if json else {"Accept": "application/xml"}
for var, val in locals().items(): for var, val in locals().items():
if str(var) == "date": if str(var) == "date":
@ -235,10 +210,9 @@ def trip_find(accessId: str,
payload[str(var)] = val payload[str(var)] = val
elif str(var) == "time": elif str(var) == "time":
if val != None: if val != None:
if isinstance(val, datetime): payload[str(var)] = (
payload[str(var)] = val.strftime("%H:%M") val.strftime("%H:%M") if isinstance(val, datetime) else val
else: )
payload[str(var)] = val
elif str(var) == "rtMode": elif str(var) == "rtMode":
if val != None: if val != None:
payload["rtMode"] = val.upper() 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) output = get("https://www.rmv.de/hapi/trip", params=payload, headers=headers)
if json: return output.json() if json else xmlparse(output.content)
return output.json()
else:
return xmlparse(output.content)

View File

@ -1,6 +1,7 @@
from datetime import datetime from datetime import datetime
from requests import get
from typing import Union from typing import Union
from requests import get
from xmltodict import parse as xmlparse from xmltodict import parse as xmlparse
try: try:
@ -8,8 +9,9 @@ try:
except ImportError: except ImportError:
from typing_extensions import Literal from typing_extensions import Literal
# 2.17. Reconstruction (recon)
def trip_recon(accessId: str, def trip_recon(
accessId: str,
ctx: str, ctx: str,
json: bool = True, json: bool = True,
poly: bool = False, poly: bool = False,
@ -38,8 +40,8 @@ def trip_recon(accessId: str,
ecoParams: Union[str, None] = None, ecoParams: Union[str, None] = None,
tariff: Union[bool, None] = None, tariff: Union[bool, None] = None,
trafficMessages: Union[bool, None] = None, trafficMessages: Union[bool, None] = None,
travellerProfileData: Union[str, None] = None travellerProfileData: Union[str, None] = None,
) -> dict: ) -> dict:
"""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
ctxRecon attribute of Trip element. The result will be a true copy of the original trip search result given 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.
@ -82,12 +84,8 @@ def trip_recon(accessId: str,
* dict: Output from RMV. Dict will contain "errorCode" and "errorText" if exception occurs. * 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 = {} payload = {}
headers = {"Accept": "application/json"} if json else {"Accept": "application/xml"}
for var, val in locals().items(): for var, val in locals().items():
if str(var) == "date": 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) output = get("https://www.rmv.de/hapi/recon", params=payload, headers=headers)
if json: return output.json() if json else xmlparse(output.content)
return output.json()
else:
return xmlparse(output.content)

View File

@ -0,0 +1,2 @@
from .find_exception import find_exception
from .weekdays_bitmask import weekdays_bitmask

View File

@ -1,9 +1,34 @@
from pyrmv.errors.api_errors import ApiAuthError, ApiFormatError, ApiParamError, ApiQuotaError, ApiTooManyRequests from pyrmv.errors import (
from pyrmv.errors.int_errors import IntError, IntGatewayError, IntTimeoutError ApiAuthError,
from pyrmv.errors.ps_errors import PsIncorrectParamError ApiFormatError,
from pyrmv.errors.sot_errors import SotAllTrainsFilteredError, SotAlreadyArrivedError, SotCancelledError, SotNotStartedError, SotStayOnTripError ApiParamError,
from pyrmv.errors.svc_errors import SvcContextError, SvcDatetimeError, SvcDatetimePeriodError, SvcLocationArrivalError, SvcLocationDepartureError, SvcLocationEqualError, SvcLocationError, SvcLocationNearError, SvcLocationViaError, SvcNoMatchError, SvcNoResultError, SvcProductError, SvcSearchError ApiQuotaError,
from pyrmv.errors.unknown_error import UnknownError ApiTooManyRequests,
IntError,
IntGatewayError,
IntTimeoutError,
PsIncorrectParamError,
SotAllTrainsFilteredError,
SotAlreadyArrivedError,
SotCancelledError,
SotNotStartedError,
SotStayOnTripError,
SvcContextError,
SvcDatetimeError,
SvcDatetimePeriodError,
SvcLocationArrivalError,
SvcLocationDepartureError,
SvcLocationEqualError,
SvcLocationError,
SvcLocationNearError,
SvcLocationViaError,
SvcNoMatchError,
SvcNoResultError,
SvcProductError,
SvcSearchError,
UnknownError,
)
def find_exception(data: dict): def find_exception(data: dict):
"""Scan returned dict for errorCode from RMV. """Scan returned dict for errorCode from RMV.
@ -16,7 +41,6 @@ def find_exception(data: dict):
* Any: Formatted as "errorCode -> errorText" if ApiParamError and UnknownError or as a single massage for others. * Any: Formatted as "errorCode -> errorText" if ApiParamError and UnknownError or as a single massage for others.
""" """
if "errorCode" in data: if "errorCode" in data:
if data["errorCode"] == "API_AUTH": if data["errorCode"] == "API_AUTH":
raise ApiAuthError() raise ApiAuthError()

View File

@ -10,12 +10,9 @@ def weekdays_bitmask(data: OrderedDict[str, bool]) -> str:
### Returns: ### Returns:
* str: _description_ * str: _description_
""" """
output = ""
if len(data) != 7: if len(data) != 7:
raise ValueError("OrderedDict must be formatted as follows: OrderedDict(Monday=bool, Tuesday=bool, Wednesday=bool, Thursday=bool, Friday=bool, Saturday=bool, Sunday=bool)") raise ValueError(
for day in data: "OrderedDict must be formatted as follows: OrderedDict(Monday=bool, Tuesday=bool, Wednesday=bool, Thursday=bool, Friday=bool, Saturday=bool, Sunday=bool)"
if data[day]: )
output += "1"
else: return "".join("1" if data[day] else "0" for day in data)
output += "0"
return output