New date and time behavior, improved typing
This commit is contained in:
@@ -1,41 +1,57 @@
|
||||
from datetime import datetime
|
||||
from typing import Any, Mapping
|
||||
from typing import Any, List, Mapping, Union
|
||||
|
||||
from pyrmv.classes.journey import Journey
|
||||
from pyrmv.classes.message import Message
|
||||
from pyrmv.classes.stop import Stop
|
||||
from pyrmv.utility import ref_upgrade
|
||||
|
||||
|
||||
class LineArrival:
|
||||
def __init__(self, data: Mapping[str, Any], client, retrieve_stops: bool = True):
|
||||
def __init__(
|
||||
self,
|
||||
data: Mapping[str, Any],
|
||||
retrieve_stops: bool = False,
|
||||
retrieve_journey: bool = False,
|
||||
client: Union["pyrmv.Client", None] = None,
|
||||
):
|
||||
if (retrieve_stops or retrieve_journey) and client is None:
|
||||
raise KeyError(
|
||||
"Stops/journey retrieval requested but client argument was not provided."
|
||||
)
|
||||
|
||||
# Upgrade is temporarily used due to RMV API mismatch
|
||||
# self.journey = client.journey_detail(data["JourneyDetailRef"]["ref"])
|
||||
self.journey = client.journey_detail(ref_upgrade(data["JourneyDetailRef"]["ref"]))
|
||||
self.journey: Union[Journey, None] = (
|
||||
client.journey_detail(ref_upgrade(data["JourneyDetailRef"]["ref"]))
|
||||
if retrieve_journey
|
||||
else None
|
||||
)
|
||||
|
||||
self.status = data["JourneyStatus"]
|
||||
self.messages = []
|
||||
self.name = data["name"]
|
||||
self.type = data["type"]
|
||||
self.stop_name = data["stop"]
|
||||
self.stop_id = data["stopid"]
|
||||
self.stop_id_ext = data["stopExtId"]
|
||||
self.stop = client.stop_by_id(self.stop_id) if retrieve_stops else None
|
||||
self.stop = client.stop_by_id(self.stop_id)
|
||||
self.time = datetime.strptime(data["time"], "%H:%M:%S")
|
||||
self.date = datetime.strptime(data["date"], "%Y-%m-%d")
|
||||
self.reachable = data["reachable"]
|
||||
self.origin = data["origin"]
|
||||
self.origin = data["origin"]
|
||||
self.status: str = data["JourneyStatus"]
|
||||
self.messages: List[Message] = []
|
||||
self.name: str = data["name"]
|
||||
self.type: str = data["type"]
|
||||
self.stop_name: str = data["stop"]
|
||||
self.stop_id: str = data["stopid"]
|
||||
self.stop_id_ext: Union[str, None] = data.get("stopExtId")
|
||||
self.stop: Union[Stop, None] = (
|
||||
client.stop_by_id(self.stop_id) if retrieve_stops else None
|
||||
)
|
||||
self.time: datetime = datetime.strptime(
|
||||
f"{data['date']} {data['time']}", "%Y-%m-%d %H:%M:%S"
|
||||
)
|
||||
self.time_real: datetime = (
|
||||
datetime.strptime(f"{data['rtDate']} {data['rtTime']}", "%Y-%m-%d %H:%M:%S")
|
||||
if data.get("rtTime") and data.get("rtDate")
|
||||
else None
|
||||
)
|
||||
self.reachable: bool = data["reachable"]
|
||||
self.origin: Union[str, None] = data.get("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:
|
||||
return (
|
||||
f"{self.name} coming from {self.origin} at {self.time.time()} {self.date.date()}"
|
||||
@@ -43,35 +59,51 @@ class LineArrival:
|
||||
|
||||
|
||||
class LineDeparture:
|
||||
def __init__(self, data: Mapping[str, Any], client, retrieve_stops: bool = True):
|
||||
def __init__(
|
||||
self,
|
||||
data: Mapping[str, Any],
|
||||
retrieve_stops: bool = False,
|
||||
retrieve_journey: bool = False,
|
||||
client: Union["pyrmv.Client", None] = None,
|
||||
):
|
||||
if (retrieve_stops or retrieve_journey) and client is None:
|
||||
raise KeyError(
|
||||
"Stops/journey retrieval requested but client argument was not provided."
|
||||
)
|
||||
|
||||
# Upgrade is temporarily used due to RMV API mismatch
|
||||
# self.journey = client.journey_detail(data["JourneyDetailRef"]["ref"])
|
||||
self.journey = client.journey_detail(ref_upgrade(data["JourneyDetailRef"]["ref"]))
|
||||
self.journey: Union[Journey, None] = (
|
||||
client.journey_detail(ref_upgrade(data["JourneyDetailRef"]["ref"]))
|
||||
if retrieve_journey
|
||||
else None
|
||||
)
|
||||
|
||||
self.status = data["JourneyStatus"]
|
||||
self.messages = []
|
||||
self.name = data["name"]
|
||||
self.type = data["type"]
|
||||
self.stop_name = data["stop"]
|
||||
self.stop_id = data["stopid"]
|
||||
self.stop_id_ext = data["stopExtId"]
|
||||
self.stop = client.stop_by_id(self.stop_id) if retrieve_stops else None
|
||||
self.time = datetime.strptime(data["time"], "%H:%M:%S")
|
||||
self.date = datetime.strptime(data["date"], "%Y-%m-%d")
|
||||
self.reachable = data["reachable"]
|
||||
self.direction = data["direction"]
|
||||
self.direction_flag = data["directionFlag"]
|
||||
self.status: str = data["JourneyStatus"]
|
||||
self.messages: List[Message] = []
|
||||
self.name: str = data["name"]
|
||||
self.type: str = data["type"]
|
||||
self.stop_name: str = data["stop"]
|
||||
self.stop_id: str = data["stopid"]
|
||||
self.stop_id_ext: Union[str, None] = data.get("stopExtId")
|
||||
self.stop: Union[Stop, None] = (
|
||||
client.stop_by_id(self.stop_id) if retrieve_stops else None
|
||||
)
|
||||
self.time: datetime = datetime.strptime(
|
||||
f"{data['date']} {data['time']}", "%Y-%m-%d %H:%M:%S"
|
||||
)
|
||||
self.time_real: datetime = (
|
||||
datetime.strptime(f"{data['rtDate']} {data['rtTime']}", "%Y-%m-%d %H:%M:%S")
|
||||
if data.get("rtTime") and data.get("rtDate")
|
||||
else None
|
||||
)
|
||||
self.reachable: bool = data["reachable"]
|
||||
self.direction: Union[str, None] = data.get("direction")
|
||||
self.direction_flag: Union[str, None] = data.get("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:
|
||||
return (
|
||||
f"{self.name} heading {self.direction} at {self.time.time()} {self.date.date()}"
|
||||
@@ -79,28 +111,70 @@ class LineDeparture:
|
||||
|
||||
|
||||
class BoardArrival(list):
|
||||
def __init__(self, data: Mapping[str, Any], client, retrieve_stops: bool = True):
|
||||
def __init__(
|
||||
self,
|
||||
data: Mapping[str, Any],
|
||||
retrieve_stops: bool = False,
|
||||
retrieve_journey: bool = False,
|
||||
client: Union["pyrmv.Client", None] = None,
|
||||
):
|
||||
"""Arrival board representation
|
||||
|
||||
### Args:
|
||||
* data (`Mapping[str, Any]`): Dictionary from RMV to be parsed.
|
||||
* retrieve_stops (`bool`, *optional*): Retrieve `Stop` objects for each line of the board. Defaults to `False`.
|
||||
* retrieve_journey (`bool`, *optional*): Retrieve `Journey` object for each line of the board. Defaults to `False`.
|
||||
* client (`Union[Client, None]`, *optional*): Client to be used if `retrieve_stops` or `retrieve_journey` are set to `True`. Defaults to `None`.
|
||||
"""
|
||||
super().__init__([])
|
||||
|
||||
if "Arrival" not in data:
|
||||
return
|
||||
|
||||
for line in data["Arrival"]:
|
||||
self.append(LineArrival(line, client, retrieve_stops=retrieve_stops))
|
||||
self.append(
|
||||
LineArrival(
|
||||
line,
|
||||
retrieve_stops=retrieve_stops,
|
||||
retrieve_journey=retrieve_journey,
|
||||
client=client,
|
||||
)
|
||||
)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return "Arrival board\n" + "\n".join([str(line) for line in self])
|
||||
|
||||
|
||||
class BoardDeparture(list):
|
||||
def __init__(self, data: Mapping[str, Any], client, retrieve_stops: bool = True):
|
||||
def __init__(
|
||||
self,
|
||||
data: Mapping[str, Any],
|
||||
retrieve_stops: bool = False,
|
||||
retrieve_journey: bool = False,
|
||||
client: Union["pyrmv.Client", None] = None,
|
||||
):
|
||||
"""Departure board representation
|
||||
|
||||
### Args:
|
||||
* data (`Mapping[str, Any]`): Dictionary from RMV to be parsed.
|
||||
* retrieve_stops (`bool`, *optional*): Retrieve `Stop` objects for each line of the board. Defaults to `False`.
|
||||
* retrieve_journey (`bool`, *optional*): Retrieve `Journey` object for each line of the board. Defaults to `False`.
|
||||
* client (`Union[Client, None]`, *optional*): Client to be used if `retrieve_stops` or `retrieve_journey` are set to `True`. Defaults to `None`.
|
||||
"""
|
||||
super().__init__([])
|
||||
|
||||
if "Departure" not in data:
|
||||
return
|
||||
|
||||
for line in data["Departure"]:
|
||||
self.append(LineDeparture(line, client, retrieve_stops=retrieve_stops))
|
||||
self.append(
|
||||
LineDeparture(
|
||||
line,
|
||||
retrieve_stops=retrieve_stops,
|
||||
retrieve_journey=retrieve_journey,
|
||||
client=client,
|
||||
)
|
||||
)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return "Departure board\n" + "\n".join([str(line) for line in self])
|
||||
|
@@ -10,7 +10,18 @@ from pyrmv.classes import (
|
||||
StopTrip,
|
||||
Trip,
|
||||
)
|
||||
from pyrmv.enums import *
|
||||
from pyrmv.enums import (
|
||||
AffectedJourneyMode,
|
||||
AffectedJourneyStopMode,
|
||||
BoardArrivalType,
|
||||
BoardDepartureType,
|
||||
FilterMode,
|
||||
Language,
|
||||
LocationType,
|
||||
RealTimeMode,
|
||||
SearchMode,
|
||||
SelectionMode,
|
||||
)
|
||||
from pyrmv.raw import board_arrival as raw_board_arrival
|
||||
from pyrmv.raw import board_departure as raw_board_departure
|
||||
from pyrmv.raw import him_search as raw_him_search
|
||||
@@ -60,7 +71,7 @@ class Client:
|
||||
board_departure = client.board_departure("A=1@O=Frankfurt (Main) Taunusanlage@X=8668765@Y=50113478@U=80@L=3000011@", journeys_max=5)
|
||||
|
||||
# Search for HIM messages for S9
|
||||
messages = client.him_search(date_end=datetime.now()+timedelta(days=10), priority_min=2, train_names=["S9"])
|
||||
messages = client.him_search(time_end=datetime.now()+timedelta(days=10), priority_min=2, train_names=["S9"])
|
||||
|
||||
# Get detailed journey of Bus 101
|
||||
journey = client.journey_detail("2|#VN#1#ST#1664906549#PI#0#ZI#12709#TA#0#DA#61022#1S#3008007#1T#1248#LS#3008043#LT#1323#PU#80#RT#1#CA#1aE#ZE#101#ZB#Bus 101 #PC#6#FR#3008007#FT#1248#TO#3008043#TT#1323#", real_time_mode=pyrmv.enums.RealTimeMode.FULL)
|
||||
@@ -77,15 +88,14 @@ class Client:
|
||||
"""
|
||||
|
||||
def __init__(self, access_id: str) -> None:
|
||||
self.access_id = access_id
|
||||
self.access_id: str = access_id
|
||||
|
||||
def board_arrival(
|
||||
self,
|
||||
id: Union[str, None] = None,
|
||||
id_ext: Union[str, None] = None,
|
||||
direction: Union[str, Stop, StopTrip, None] = None,
|
||||
date: Union[str, datetime, None] = None,
|
||||
time: Union[str, datetime, None] = None,
|
||||
time: Union[datetime, None] = None,
|
||||
duration: Union[int, timedelta] = 60,
|
||||
journeys_max: int = -1,
|
||||
operators: Union[str, list, None] = None,
|
||||
@@ -98,6 +108,7 @@ class Client:
|
||||
BoardArrivalType.ARR_STATION,
|
||||
] = BoardArrivalType.ARR,
|
||||
retrieve_stops: bool = True,
|
||||
retrieve_journey: bool = True,
|
||||
) -> BoardArrival:
|
||||
"""Method returns a board with arriving transport.
|
||||
|
||||
@@ -107,15 +118,15 @@ class Client:
|
||||
* id (`str`, **optional**): Specifies the station/stop ID. Such ID can be retrieved from stop_by_name() or stop_by_coords(). Defaults to `None`.
|
||||
* id_ext (`str`, **optional**): Deprecated. Please use `id` as it supports external IDs. Specifies the external station/stop ID. Such ID can be retrieved from stop_by_name() or stop_by_coords(). Defaults to `None`.
|
||||
* direction (`Union[str, Stop, StopTrip]`, **optional**): If only vehicles departing or arriving from a certain direction shall be returned, specify the direction by giving the station/stop ID of the last stop on the journey or the Stop object itself. Defaults to `None`.
|
||||
* date (`Union[str, datetime]`, **optional**): Sets the start date for which the departures shall be retrieved. Represented in the format YYYY-MM-DD or as a datetime object. By default the current server date is used. Defaults to `None`.
|
||||
* time (`Union[str, datetime]`, **optional**): Sets the start time for which the departures shall be retrieved. Represented in the format hh:mm[:ss] in 24h nomenclature or as a datetime object. Seconds will be ignored for requests. By default the current server time is used. Defaults to `None`.
|
||||
* time (`datetime`, **optional**): Sets the start time for which the departures shall be retrieved. Represented as a datetime object. Seconds will be ignored for requests. By default the current server time is used. Defaults to `None`.
|
||||
* duration (`Union[int, timedelta]`, **optional**): Set the interval size in minutes. Can also be provided as a timedelta. Defaults to `60`.
|
||||
* journeys_max (`int`, **optional**): Maximum number of journeys to be returned. If no value is defined or -1, all departing/arriving services within the duration sized period are returned. Defaults to `-1`.
|
||||
* operators (`Union[str, list]`, **optional**): Only journeys provided by the given operators are part of the result. To filter multiple operators, separate the codes by comma or provide a list. If the operator should not be part of the be trip, negate it by putting ! in front of it. Example: Filter for operator A and B: `operators=[A,B]`. Defaults to `None`.
|
||||
* lines (`Union[str, list]`, **optional**): Only journeys running the given line are part of the result. To filter multiple lines, provide a list or separate the codes by comma or provide a list. If the line should not be part of the be trip, negate it by putting ! in front of it. Defaults to `None`.
|
||||
* passlist (`bool`, **optional**): Include a list of all passed waystops. Defaults to `False`.
|
||||
* board_type (`Union[BoardArrivalType.ARR, BoardArrivalType.ARR_EQUIVS, BoardArrivalType.ARR_MAST, BoardArrivalType.ARR_STATION]`, optional): Set the station arrival board type to be used. Defaults to `BoardArrivalType.ARR`.
|
||||
* board_type (`Union[BoardArrivalType.ARR, BoardArrivalType.ARR_EQUIVS, BoardArrivalType.ARR_MAST, BoardArrivalType.ARR_STATION]`, *optional*): Set the station arrival board type to be used. Defaults to `BoardArrivalType.ARR`.
|
||||
* retrieve_stops (`bool`, **optional**): Whether the stops should be retrieved as a `Stop` objects. Using `False` will drastically increase processing speed and decrease number of requests made (good for low access_key rate limit). Defaults to `True`.
|
||||
* retrieve_journey (`bool`, **optional**): Whether the journey should be retrieved as a `Journey` object. Using `False` will increase processing speed and decrease number of requests made (good for low access_key rate limit). Defaults to `True`.
|
||||
|
||||
### Returns:
|
||||
* BoardArrival: Instance of `BoardArrival` object.
|
||||
@@ -129,7 +140,7 @@ class Client:
|
||||
id=id,
|
||||
extId=id_ext,
|
||||
direction=direction, # type: ignore
|
||||
date=date,
|
||||
date=time,
|
||||
time=time,
|
||||
duration=duration,
|
||||
maxJourneys=journeys_max,
|
||||
@@ -141,15 +152,19 @@ class Client:
|
||||
|
||||
find_exception(board_raw)
|
||||
|
||||
return BoardArrival(board_raw, self, retrieve_stops=retrieve_stops)
|
||||
return BoardArrival(
|
||||
board_raw,
|
||||
retrieve_stops=retrieve_stops,
|
||||
retrieve_journey=retrieve_journey,
|
||||
client=self,
|
||||
)
|
||||
|
||||
def board_departure(
|
||||
self,
|
||||
id: Union[str, None] = None,
|
||||
id_ext: Union[str, None] = None,
|
||||
direction: Union[str, Stop, StopTrip, None] = None,
|
||||
date: Union[str, datetime, None] = None,
|
||||
time: Union[str, datetime, None] = None,
|
||||
time: Union[datetime, None] = None,
|
||||
duration: Union[int, timedelta] = 60,
|
||||
journeys_max: int = -1,
|
||||
operators: Union[str, list, None] = None,
|
||||
@@ -162,6 +177,7 @@ class Client:
|
||||
BoardDepartureType.DEP_STATION,
|
||||
] = BoardDepartureType.DEP,
|
||||
retrieve_stops: bool = True,
|
||||
retrieve_journey: bool = True,
|
||||
) -> BoardDeparture:
|
||||
"""Method returns a board with departing transport.
|
||||
|
||||
@@ -171,15 +187,15 @@ class Client:
|
||||
* id (`str`, **optional**): Specifies the station/stop ID. Such ID can be retrieved from stop_by_name() or stop_by_coords(). Defaults to `None`.
|
||||
* id_ext (`str`, **optional**): Deprecated. Please use `id` as it supports external IDs. Specifies the external station/stop ID. Such ID can be retrieved from stop_by_name() or stop_by_coords(). Defaults to `None`.
|
||||
* direction (`Union[str, Stop, StopTrip]`, **optional**): If only vehicles departing or arriving from a certain direction shall be returned, specify the direction by giving the station/stop ID of the last stop on the journey or the Stop object itself. Defaults to `None`.
|
||||
* date (`Union[str, datetime]`, **optional**): Sets the start date for which the departures shall be retrieved. Represented in the format YYYY-MM-DD or as a datetime object. By default the current server date is used. Defaults to `None`.
|
||||
* time (`Union[str, datetime]`, **optional**): Sets the start time for which the departures shall be retrieved. Represented in the format hh:mm[:ss] in 24h nomenclature or as a datetime object. Seconds will be ignored for requests. By default the current server time is used. Defaults to `None`.
|
||||
* time (`datetime`, **optional**): Sets the start time for which the departures shall be retrieved. Represented as a datetime object. Seconds will be ignored for requests. By default the current server time is used. Defaults to `None`.
|
||||
* duration (`Union[int, timedelta]`, **optional**): Set the interval size in minutes. Can also be provided as a timedelta. Defaults to `60`.
|
||||
* journeys_max (`int`, **optional**): Maximum number of journeys to be returned. If no value is defined or -1, all departing/arriving services within the duration sized period are returned. Defaults to `-1`.
|
||||
* operators (`Union[str, list]`, **optional**): Only journeys provided by the given operators are part of the result. To filter multiple operators, separate the codes by comma or provide a list. If the operator should not be part of the be trip, negate it by putting ! in front of it. Example: Filter for operator A and B: `operators=[A,B]`. Defaults to `None`.
|
||||
* lines (`Union[str, list]`, **optional**): Only journeys running the given line are part of the result. To filter multiple lines, provide a list or separate the codes by comma or provide a list. If the line should not be part of the be trip, negate it by putting ! in front of it. Defaults to `None`.
|
||||
* passlist (`bool`, **optional**): Include a list of all passed waystops. Defaults to `False`.
|
||||
* board_type (`Union[BoardDepartureType.DEP, BoardDepartureType.DEP_EQUIVS, BoardDepartureType.DEP_MAST, BoardDepartureType.DEP_STATION]`, optional): Set the station departure board type to be used. Defaults to `BoardDepartureType.DEP`.
|
||||
* board_type (`Union[BoardDepartureType.DEP, BoardDepartureType.DEP_EQUIVS, BoardDepartureType.DEP_MAST, BoardDepartureType.DEP_STATION]`, *optional*): Set the station departure board type to be used. Defaults to `BoardDepartureType.DEP`.
|
||||
* retrieve_stops (`bool`, **optional**): Whether the stops should be retrieved as a `Stop` objects. Using `False` will drastically increase processing speed and decrease number of requests made (good for low access_key rate limit). Defaults to `True`.
|
||||
* retrieve_journey (`bool`, **optional**): Whether the journey should be retrieved as a `Journey` object. Using `False` will increase processing speed and decrease number of requests made (good for low access_key rate limit). Defaults to `True`.
|
||||
|
||||
### Returns:
|
||||
* BoardDeparture: Instance of `BoardDeparture` object.
|
||||
@@ -193,7 +209,7 @@ class Client:
|
||||
id=id,
|
||||
extId=id_ext,
|
||||
direction=direction, # type: ignore
|
||||
date=date,
|
||||
date=time,
|
||||
time=time,
|
||||
duration=duration,
|
||||
maxJourneys=journeys_max,
|
||||
@@ -205,14 +221,17 @@ class Client:
|
||||
|
||||
find_exception(board_raw)
|
||||
|
||||
return BoardDeparture(board_raw, self, retrieve_stops=retrieve_stops)
|
||||
return BoardDeparture(
|
||||
board_raw,
|
||||
retrieve_stops=retrieve_stops,
|
||||
retrieve_journey=retrieve_journey,
|
||||
client=self,
|
||||
)
|
||||
|
||||
def him_search(
|
||||
self,
|
||||
date_begin: Union[str, datetime, None] = None,
|
||||
date_end: Union[str, datetime, None] = None,
|
||||
time_begin: Union[str, datetime, None] = None,
|
||||
time_end: Union[str, datetime, None] = None,
|
||||
time_begin: Union[datetime, None] = None,
|
||||
time_end: Union[datetime, None] = None,
|
||||
weekdays: Union[str, OrderedDict[str, bool], None] = None,
|
||||
ids: Union[list, None] = None,
|
||||
operators: Union[list, None] = None,
|
||||
@@ -249,28 +268,26 @@ class Client:
|
||||
More detailed request is available as `raw.him_search()`, however returns `dict` instead of `List[Message]`.
|
||||
|
||||
### Args:
|
||||
* date_begin (`Union[str, datetime]`, optional): Sets the event period start date. Defaults to `None`.
|
||||
* date_end (`Union[str, datetime]`, optional): Sets the event period end date. Defaults to `None`.
|
||||
* time_begin (`Union[str, datetime]`, optional): Sets the event period start time. Defaults to `None`.
|
||||
* time_end (`Union[str, datetime]`, optional): Sets the event period end time. Defaults to `None`.
|
||||
* weekdays (`Union[str, OrderedDict[str, bool]]`, optional): Bitmask or an OrderedDict for validity of HIM messages based on weekdays. OrderedDict must be formatted as follows: `OrderedDict(Monday=bool, Tuesday=bool, Wednesday=bool, Thursday=bool, Friday=bool, Saturday=bool, Sunday=bool)`. Each character of a bitmask represents a weekday starting on monday. Example: Only find HIM Messages valid from monday to friday: `1111100`. Defaults to `None`.
|
||||
* ids (`list`, optional): List of HIM message IDs as a list or separated by comma. Defaults to `None`.
|
||||
* operators (`list`, optional): List of operators as a list or separated by comma. Defaults to `None`.
|
||||
* categories (`list`, optional): List of train categories as a list or separated by comma. Defaults to `None`.
|
||||
* channels (`list`, optional): List of channels as a list or separated by comma. Defaults to `None`.
|
||||
* companies (`list`, optional): List of companies as a list or separated by comma. Defaults to `None`.
|
||||
* lines (`list`, optional): Only HIM messages for the given line are part of the result. To filter multiple lines, provide them as a list or separate the codes by comma. Defaults to `None`.
|
||||
* line_ids (`list`, optional): Only HIM messages for the given line (identified by its line ID) are part of the result. To filter multiple lines, provide them as a list or separate the line IDs by comma. Defaults to `None`.
|
||||
* stations (`Union[list, List[Stop]]`, optional): List of (external) station ids or a list of `Stop` objects to be filtered for as a list or separated by comma. Defaults to `None`.
|
||||
* station_from (`Union[str, Stop]`, optional): Filter messages by line segment starting at this station given as (external) station id or as a `Stop` object. Defaults to `None`.
|
||||
* station_to (`Union[str, Stop]`, optional): Filter messages by line segment travelling in direction of this station given as (external) station id or as a `Stop` object. Defaults to `None`.
|
||||
* both_ways (`bool`, optional): If enabled, messages in both directions - from 'station_from' to 'station_to' as well as from 'station_to' to 'station_from' are returned. Defaults to `None`.
|
||||
* train_names (`list`, optional): List of train name to be filtered for seperated by comma. Defaults to `None`.
|
||||
* search_mode (`Literal[SearchMode.MATCH, SearchMode.NOMATCH, SearchMode.TFMATCH]`, optional): HIM search mode. `SearchMode.NOMATCH` iterate over all HIM messages available. `SearchMode.MATCH` iterate over all trips to find HIM messages. `SearchMode.TFMATCH` uses filters defined `metas` parameter. Defaults to `None`.
|
||||
* affected_journey_mode (`Literal[AffectedJourneyMode.ALL, AffectedJourneyMode.OFF]`, optional): Define how to return affected journeys `AffectedJourneyMode.OFF`: do not return affected journeys. `AffectedJourneyMode.ALL`: return affected journeys. Defaults to `None`.
|
||||
* affected_journey_stop_mode (`Literal[AffectedJourneyStopMode.ALL, AffectedJourneyStopMode.IMP, AffectedJourneyStopMode.OFF]`, optional): Define how to return stops of affected journeys. `AffectedJourneyStopMode.IMP`: return important stops of affected journeys. `AffectedJourneyStopMode.OFF`: do not return stops of affected journeys. `AffectedJourneyStopMode.ALL`: return all affected stops of affected journeys. Defaults to `None`.
|
||||
* priority_min (`int`, optional): Filter for HIM messages having at least this priority. Defaults to `None`.
|
||||
* priority_max (`int`, optional): Filter for HIM messages having this priority as maximum. Defaults to `None`.
|
||||
* time_begin (`datetime`, *optional*): Sets the event period start time. Represented as a datetime object. Defaults to `None`.
|
||||
* time_end (`datetime`, *optional*): Sets the event period end time. Represented as a datetime object. Defaults to `None`.
|
||||
* weekdays (`Union[str, OrderedDict[str, bool]]`, *optional*): Bitmask or an OrderedDict for validity of HIM messages based on weekdays. OrderedDict must be formatted as follows: `OrderedDict(Monday=bool, Tuesday=bool, Wednesday=bool, Thursday=bool, Friday=bool, Saturday=bool, Sunday=bool)`. Each character of a bitmask represents a weekday starting on monday. Example: Only find HIM Messages valid from monday to friday: `1111100`. Defaults to `None`.
|
||||
* ids (`list`, *optional*): List of HIM message IDs as a list or separated by comma. Defaults to `None`.
|
||||
* operators (`list`, *optional*): List of operators as a list or separated by comma. Defaults to `None`.
|
||||
* categories (`list`, *optional*): List of train categories as a list or separated by comma. Defaults to `None`.
|
||||
* channels (`list`, *optional*): List of channels as a list or separated by comma. Defaults to `None`.
|
||||
* companies (`list`, *optional*): List of companies as a list or separated by comma. Defaults to `None`.
|
||||
* lines (`list`, *optional*): Only HIM messages for the given line are part of the result. To filter multiple lines, provide them as a list or separate the codes by comma. Defaults to `None`.
|
||||
* line_ids (`list`, *optional*): Only HIM messages for the given line (identified by its line ID) are part of the result. To filter multiple lines, provide them as a list or separate the line IDs by comma. Defaults to `None`.
|
||||
* stations (`Union[list, List[Stop]]`, *optional*): List of (external) station ids or a list of `Stop` objects to be filtered for as a list or separated by comma. Defaults to `None`.
|
||||
* station_from (`Union[str, Stop]`, *optional*): Filter messages by line segment starting at this station given as (external) station id or as a `Stop` object. Defaults to `None`.
|
||||
* station_to (`Union[str, Stop]`, *optional*): Filter messages by line segment travelling in direction of this station given as (external) station id or as a `Stop` object. Defaults to `None`.
|
||||
* both_ways (`bool`, *optional*): If enabled, messages in both directions - from 'station_from' to 'station_to' as well as from 'station_to' to 'station_from' are returned. Defaults to `None`.
|
||||
* train_names (`list`, *optional*): List of train name to be filtered for seperated by comma. Defaults to `None`.
|
||||
* search_mode (`Literal[SearchMode.MATCH, SearchMode.NOMATCH, SearchMode.TFMATCH]`, *optional*): HIM search mode. `SearchMode.NOMATCH` iterate over all HIM messages available. `SearchMode.MATCH` iterate over all trips to find HIM messages. `SearchMode.TFMATCH` uses filters defined `metas` parameter. Defaults to `None`.
|
||||
* affected_journey_mode (`Literal[AffectedJourneyMode.ALL, AffectedJourneyMode.OFF]`, *optional*): Define how to return affected journeys `AffectedJourneyMode.OFF`: do not return affected journeys. `AffectedJourneyMode.ALL`: return affected journeys. Defaults to `None`.
|
||||
* affected_journey_stop_mode (`Literal[AffectedJourneyStopMode.ALL, AffectedJourneyStopMode.IMP, AffectedJourneyStopMode.OFF]`, *optional*): Define how to return stops of affected journeys. `AffectedJourneyStopMode.IMP`: return important stops of affected journeys. `AffectedJourneyStopMode.OFF`: do not return stops of affected journeys. `AffectedJourneyStopMode.ALL`: return all affected stops of affected journeys. Defaults to `None`.
|
||||
* priority_min (`int`, *optional*): Filter for HIM messages having at least this priority. Defaults to `None`.
|
||||
* priority_max (`int`, *optional*): Filter for HIM messages having this priority as maximum. Defaults to `None`.
|
||||
|
||||
### Returns:
|
||||
* List[Message]: List of `Message` objects. Empty list if none found.
|
||||
@@ -302,8 +319,8 @@ class Client:
|
||||
messages = []
|
||||
messages_raw = raw_him_search(
|
||||
accessId=self.access_id,
|
||||
dateB=date_begin,
|
||||
dateE=date_end,
|
||||
dateB=time_begin,
|
||||
dateE=time_end,
|
||||
timeB=time_begin,
|
||||
timeE=time_end,
|
||||
weekdays=weekdays,
|
||||
@@ -394,18 +411,30 @@ class Client:
|
||||
coords_lat: Union[str, float],
|
||||
coords_lon: Union[str, float],
|
||||
lang: Literal[
|
||||
Language.DE,
|
||||
Language.AR,
|
||||
Language.CA,
|
||||
Language.DA,
|
||||
Language.DE,
|
||||
Language.EL,
|
||||
Language.EN,
|
||||
Language.ES,
|
||||
Language.FI,
|
||||
Language.FR,
|
||||
Language.HI,
|
||||
Language.HR,
|
||||
Language.HU,
|
||||
Language.IT,
|
||||
Language.NL,
|
||||
Language.NO,
|
||||
Language.PL,
|
||||
Language.RU,
|
||||
Language.SK,
|
||||
Language.SL,
|
||||
Language.SV,
|
||||
Language.TL,
|
||||
Language.TR,
|
||||
Language.UR,
|
||||
Language.ZH,
|
||||
] = Language.EN,
|
||||
radius: Union[int, float] = 1000,
|
||||
max_number: int = 10,
|
||||
@@ -428,7 +457,7 @@ class Client:
|
||||
### Args:
|
||||
* coords_lat (`Union[str, float]`): Latitude of centre coordinate.
|
||||
* coords_lon (`Union[str, float]`): Longitude of centre coordinate.
|
||||
* lang (`Literal[Language.DE, Language.DA, Language.EN, Language.ES, Language.FR, Language.HU, Language.IT, Language.NL, Language.NO, Language.PL, Language.SV, Language.TR]`, **optional**): The language of response. Defaults to `Language.EN`.
|
||||
* lang (`Literal[Language.AR, Language.CA, Language.DA, Language.DE, Language.EL, Language.EN, Language.ES, Language.FI, Language.FR, Language.HI, Language.HR, Language.HU, Language.IT, Language.NL, Language.NO, Language.PL, Language.RU, Language.SK, Language.SL, Language.SV, Language.TL, Language.TR, Language.UR, Language.ZH]`, **optional**): The language of response. Defaults to `Language.EN`.
|
||||
* radius (`Union[int, float]`, **optional**): Search radius in meter around the given coordinate if any. Defaults to `1000`.
|
||||
* max_number (`int`, **optional**): Maximum number of returned stops. Defaults to `10`.
|
||||
* stop_type (`Literal[LocationType.S, LocationType.P, LocationType.SP, LocationType.SE, LocationType.SPE]`, **optional**): Type filter for location types. Defaults to `LocationType.S`.
|
||||
@@ -467,25 +496,37 @@ class Client:
|
||||
self,
|
||||
query: str,
|
||||
lang: Literal[
|
||||
Language.DE,
|
||||
Language.AR,
|
||||
Language.CA,
|
||||
Language.DA,
|
||||
Language.DE,
|
||||
Language.EL,
|
||||
Language.EN,
|
||||
Language.ES,
|
||||
Language.FI,
|
||||
Language.FR,
|
||||
Language.HI,
|
||||
Language.HR,
|
||||
Language.HU,
|
||||
Language.IT,
|
||||
Language.NL,
|
||||
Language.NO,
|
||||
Language.PL,
|
||||
Language.RU,
|
||||
Language.SK,
|
||||
Language.SL,
|
||||
Language.SV,
|
||||
Language.TL,
|
||||
Language.TR,
|
||||
Language.UR,
|
||||
Language.ZH,
|
||||
] = Language.EN,
|
||||
) -> Union[Stop, None]:
|
||||
"""Method can be used to get Stop object whilst only having id available.
|
||||
|
||||
### Args:
|
||||
* query (`str`): Search for that token.
|
||||
* lang (`Literal[Language.DE, Language.DA, Language.EN, Language.ES, Language.FR, Language.HU, Language.IT, Language.NL, Language.NO, Language.PL, Language.SV, Language.TR]`, **optional**): The language of response. Defaults to `Language.EN`.
|
||||
* lang (`Literal[Language.AR, Language.CA, Language.DA, Language.DE, Language.EL, Language.EN, Language.ES, Language.FI, Language.FR, Language.HI, Language.HR, Language.HU, Language.IT, Language.NL, Language.NO, Language.PL, Language.RU, Language.SK, Language.SL, Language.SV, Language.TL, Language.TR, Language.UR, Language.ZH]`, **optional**): The language of response. Defaults to `Language.EN`.
|
||||
|
||||
### Returns:
|
||||
* Union[Stop, None]: Instance of `Stop` object or `None` if not found.
|
||||
@@ -513,18 +554,30 @@ class Client:
|
||||
self,
|
||||
query: str,
|
||||
lang: Literal[
|
||||
Language.DE,
|
||||
Language.AR,
|
||||
Language.CA,
|
||||
Language.DA,
|
||||
Language.DE,
|
||||
Language.EL,
|
||||
Language.EN,
|
||||
Language.ES,
|
||||
Language.FI,
|
||||
Language.FR,
|
||||
Language.HI,
|
||||
Language.HR,
|
||||
Language.HU,
|
||||
Language.IT,
|
||||
Language.NL,
|
||||
Language.NO,
|
||||
Language.PL,
|
||||
Language.RU,
|
||||
Language.SK,
|
||||
Language.SL,
|
||||
Language.SV,
|
||||
Language.TL,
|
||||
Language.TR,
|
||||
Language.UR,
|
||||
Language.ZH,
|
||||
] = Language.EN,
|
||||
max_number: int = 10,
|
||||
stop_type: Literal[
|
||||
@@ -556,7 +609,7 @@ class Client:
|
||||
|
||||
### Args:
|
||||
* query (`str`): Search for that token.
|
||||
* lang (`Literal[Language.DE, Language.DA, Language.EN, Language.ES, Language.FR, Language.HU, Language.IT, Language.NL, Language.NO, Language.PL, Language.SV, Language.TR]`, **optional**): The language of response. Defaults to `Language.EN`.
|
||||
* lang (`Literal[Language.AR, Language.CA, Language.DA, Language.DE, Language.EL, Language.EN, Language.ES, Language.FI, Language.FR, Language.HI, Language.HR, Language.HU, Language.IT, Language.NL, Language.NO, Language.PL, Language.RU, Language.SK, Language.SL, Language.SV, Language.TL, Language.TR, Language.UR, Language.ZH]`, **optional**): The language of response. Defaults to `Language.EN`.
|
||||
* max_number (`int`, **optional**): Maximum number of returned stops. In range 1-1000. Defaults to `10`.
|
||||
* stop_type (`Literal[LocationType.A, LocationType.ALL, LocationType.AP, LocationType.P, LocationType.S, LocationType.SA, LocationType.SP]`, **optional**): Type filter for location types. Defaults to `LocationType.ALL`.
|
||||
* selection_mode (`Literal[SelectionMode.SLCT_A, SelectionMode.SLCT_N]`, **optional**): Selection mode for locations. `SelectionMode.SLCT_N`: Not selectable, `SelectionMode.SLCT_A`: Selectable. Defaults to `None`.
|
||||
@@ -603,18 +656,30 @@ class Client:
|
||||
def trip_find(
|
||||
self,
|
||||
lang: Literal[
|
||||
Language.DE,
|
||||
Language.AR,
|
||||
Language.CA,
|
||||
Language.DA,
|
||||
Language.DE,
|
||||
Language.EL,
|
||||
Language.EN,
|
||||
Language.ES,
|
||||
Language.FI,
|
||||
Language.FR,
|
||||
Language.HI,
|
||||
Language.HR,
|
||||
Language.HU,
|
||||
Language.IT,
|
||||
Language.NL,
|
||||
Language.NO,
|
||||
Language.PL,
|
||||
Language.RU,
|
||||
Language.SK,
|
||||
Language.SL,
|
||||
Language.SV,
|
||||
Language.TL,
|
||||
Language.TR,
|
||||
Language.UR,
|
||||
Language.ZH,
|
||||
] = Language.EN,
|
||||
origin_id: Union[str, None] = None,
|
||||
origin_id_ext: Union[str, None] = None,
|
||||
@@ -637,8 +702,7 @@ class Client:
|
||||
change_time_max: Union[int, None] = None,
|
||||
change_time_add: Union[int, None] = None,
|
||||
change_max: Union[int, None] = None,
|
||||
date: Union[str, datetime, None] = None,
|
||||
time: Union[str, datetime, None] = None,
|
||||
time: Union[datetime, None] = None,
|
||||
search_arrival: bool = False,
|
||||
trips_after_time: Union[int, None] = None,
|
||||
trips_before_time: Union[int, None] = None,
|
||||
@@ -674,7 +738,7 @@ class Client:
|
||||
More detailed request is available as `raw.trip_find()`, however returns `dict` instead of `List[Trip]`.
|
||||
|
||||
### Args:
|
||||
* lang (`Literal[Language.DE, Language.DA, Language.EN, Language.ES, Language.FR, Language.HU, Language.IT, Language.NL, Language.NO, Language.PL, Language.SV, Language.TR]`, **optional**): The language of response. Defaults to `Language.EN`.
|
||||
* lang (`Literal[Language.AR, Language.CA, Language.DA, Language.DE, Language.EL, Language.EN, Language.ES, Language.FI, Language.FR, Language.HI, Language.HR, Language.HU, Language.IT, Language.NL, Language.NO, Language.PL, Language.RU, Language.SK, Language.SL, Language.SV, Language.TL, Language.TR, Language.UR, Language.ZH]`, **optional**): The language of response. Defaults to `Language.EN`.
|
||||
* origin_id (`str`, **optional**): Specifies the station/stop ID of the origin for the trip. Such ID can be retrieved from stop_by_name() or stop_by_coords(). Defaults to `None`.
|
||||
* origin_id_ext (`str`, **optional**): Deprecated. Please use originId as it supports external IDs. Specifies the external station/stop ID of the origin for the trip. Such ID can be retrieved from stop_by_name() or stop_by_coords(). Defaults to `None`.
|
||||
* origin_coord_lat (`Union[str, float]`, **optional**): Latitude of station/stop coordinate of the trip's origin. The coordinate can be retrieved from stop_by_name() or stop_by_coords(). Defaults to `None`.
|
||||
@@ -689,15 +753,14 @@ class Client:
|
||||
* via_id (`str`, **optional**): ID of a station/stop used as a via for the trip. Specifying a via station forces the trip search to look for trips which must pass through this station. Such ID can be retrieved from stop_by_name() or stop_by_coords(). If `via` is used, `via_id` and `via_wait_time ` are having no effect. Defaults to `None`.
|
||||
* via_gis (`str`, **optional**): Complex structure to provide multiple GIS via locations separated by semicolon. This structure is build like this: `locationId|locationMode|transportMode|placeType|usageType|mode|durationOfStay`. Read more about this in HAFAS ReST Documentation. Defaults to `None`.
|
||||
* via_wait_time (`int`, **optional**): Defines the waiting time spent at via station in minutes. If `via` is used, `via_id` and `via_wait_time` are having no effect. Defaults to 0.
|
||||
* avoid (`str`, **optional**): Complex structure to provide multiple points to be avoided separated by semicolon. This structure is build like this: `avoidId|avoidstatus` avoidId: id, extId or altId of the avoid, mandatory avoidstatus: one of NPAVM (do not run through if this is a meta station), NPAVO (do not run through), NCAVM (do not change if this is a meta station), NCAVO (do not change), optional but defaults to NCAVM Example: Just define three avoids by extId: `avoid="801234;801235;801236"`. Defaults to `None`.
|
||||
* avoid (`str`, **optional**): Complex structure to provide multiple points to be avoided separated by semicolon. This structure is build like this: `avoidId|avoidstatus` avoidId: id, extId or altId of the avoid, mandatory avoidstatus: one of NPAVM (do not run through if this is a meta station), NPAVO (do not run through), NCAVM (do not change if this is a meta station), NCAVO (do not change), *optional* but defaults to NCAVM Example: Just define three avoids by extId: `avoid="801234;801235;801236"`. Defaults to `None`.
|
||||
* avoid_id (`str`, **optional**): ID of a station/stop to be avoided as transfer stop for the trip. Such ID can be retrieved from stop_by_name() or stop_by_coords(). If `avoid` is used, `avoid_id` has no effect. Defaults to `None`.
|
||||
* change_time_percent (`int`, **optional**): Configures the walking speed when changing from one leg of the journey to the next one. It extends the time required for changes by a specified percentage. A value of 200 doubles the change time as initially calculated by the system. In the response, change time is presented in full minutes. If the calculation based on changeTime-Percent does not result in a full minute, it is rounded using "round half up" method. Defaults to `100`.
|
||||
* change_time_min (`int`, **optional**): Minimum change time at stop in minutes. Defaults to `None`.
|
||||
* change_time_max (`int`, **optional**): Maximum change time at stop in minutes. Defaults to `None`.
|
||||
* change_time_add (`int`, **optional**): This amount of minutes is added to the change time at each stop. Defaults to `None`.
|
||||
* change_max (`int`, **optional**): Maximum number of changes. In range 0-11. Defaults to `None`.
|
||||
* date (`Union[str, datetime]`, **optional**): Sets the start date for which the departures shall be retrieved. Represented in the format `YYYY-MM-DD` or as a datetime object. By default the current server date is used. Defaults to `None`.
|
||||
* time (`Union[str, datetime]`, **optional**): Sets the start time for which the departures shall be retrieved. Represented in the format `hh:mm[:ss]` in 24h nomenclature or as a datetime object. Seconds will be ignored for requests. By default the current server time is used. Defaults to `None`.
|
||||
* time (`datetime`, **optional**): Sets the start time for which the departures shall be retrieved. Represented as a datetime object. Seconds will be ignored for requests. By default the current server time is used. Defaults to `None`.
|
||||
* search_arrival (`bool`, **optional**): If set, the date and time parameters specify the arrival time for the trip search instead of the departure time. Defaults to `False`.
|
||||
* trips_after_time (`int`, **optional**): Minimum number of trips after the search time. Sum of `trips_after_time` and `trips_before_time` has to be less or equal 6. Read more about this in HAFAS ReST Documentation. In range 1-6. Defaults to `None`.
|
||||
* trips_before_time (`int`, **optional**): Minimum number of trips before the search time. Sum of `trips_after_time` and `trips_before_time` has to be less or equal 6. Read more about this in HAFAS ReST Documentation. In range 0-6. Defaults to `None`.
|
||||
@@ -748,7 +811,7 @@ class Client:
|
||||
maxChangeTime=change_time_max,
|
||||
addChangeTime=change_time_add,
|
||||
maxChange=change_max,
|
||||
date=date,
|
||||
date=time,
|
||||
time=time,
|
||||
searchForArrival=search_arrival,
|
||||
numF=trips_after_time,
|
||||
@@ -780,7 +843,7 @@ class Client:
|
||||
def trip_recon(
|
||||
self,
|
||||
context: Union[str, Trip],
|
||||
date: Union[str, datetime, None] = None,
|
||||
date: Union[datetime, None] = None,
|
||||
match_real_time: Union[bool, None] = None,
|
||||
enable_replacements: Union[bool, None] = None,
|
||||
arrival_dev_lower: Union[int, None] = None,
|
||||
@@ -810,7 +873,7 @@ class Client:
|
||||
|
||||
### Args:
|
||||
* context (`Union[str, Journey]`): Specifies the reconstruction context.
|
||||
* date (`Union[str, datetime]`, **optional**): Sets the start date for which the departures shall be retrieved. Represented in the format `YYYY-MM-DD` or as a datetime object. This parameter will force the service to reconstruct the trip on that specific date. If the trip is not available on that date, because it does not operate, exception SvcNoResultError will be raised. Defaults to `None`.
|
||||
* date (`datetime`, **optional**): Sets the start date for which the departures shall be retrieved. Represented as a datetime object. This parameter will force the service to reconstruct the trip on that specific date. If the trip is not available on that date, because it does not operate, exception SvcNoResultError will be raised. Defaults to `None`.
|
||||
* match_real_time (`bool`, **optional**): Whether the realtime type that journeys are based on be considered. Defaults to `None`.
|
||||
* enable_replacements (`bool`, **optional**): If set to `True` replaces cancelled journeys with their replacement journeys if possible. Defaults to `None`.
|
||||
* arrival_dev_lower (`int`, **optional**): Lower deviation in minutes within interval `[0, 720]` indicating "how much earlier than original arrival". Defaults to `None`.
|
||||
|
@@ -1,13 +1,14 @@
|
||||
from typing import Any, Mapping
|
||||
from datetime import timedelta
|
||||
from typing import Any, Mapping, Union
|
||||
|
||||
from isodate import parse_duration
|
||||
from isodate import Duration, parse_duration
|
||||
|
||||
|
||||
class Gis:
|
||||
"""Gis object."""
|
||||
|
||||
def __init__(self, ref: str, route: Mapping[str, Any]):
|
||||
self.ref = ref
|
||||
self.dist = route["dist"]
|
||||
self.duration = parse_duration(route["durS"])
|
||||
self.geo = route["dirGeo"]
|
||||
self.ref: str = ref
|
||||
self.dist: Union[int, None] = route.get("dist")
|
||||
self.duration: Union[Duration, timedelta] = parse_duration(route["durS"])
|
||||
self.geo: Union[int, None] = route.get("dirGeo")
|
||||
|
@@ -1,4 +1,4 @@
|
||||
from typing import Any, Mapping
|
||||
from typing import Any, List, Mapping, Union
|
||||
|
||||
from pyrmv.classes.message import Message
|
||||
from pyrmv.classes.stop import Stop
|
||||
@@ -9,16 +9,24 @@ class Journey:
|
||||
"""Journey object."""
|
||||
|
||||
def __init__(self, data: Mapping[str, Any]):
|
||||
self.stops = []
|
||||
self.stops: List[Stop] = []
|
||||
|
||||
# Upgrade is temporarily used due to RMV API mismatch
|
||||
# self.ref = data["ref"]
|
||||
self.ref = ref_upgrade(data["ref"])
|
||||
self.ref: str = ref_upgrade(data["ref"])
|
||||
|
||||
self.direction = data["Directions"]["Direction"][0]["value"]
|
||||
self.direction_flag = data["Directions"]["Direction"][0]["flag"]
|
||||
self.direction: Union[str, None] = (
|
||||
data["Directions"]["Direction"][0].get("value")
|
||||
if data["Directions"]["Direction"]
|
||||
else None
|
||||
)
|
||||
self.direction_flag: Union[str, None] = (
|
||||
data["Directions"]["Direction"][0].get("flag")
|
||||
if data["Directions"]["Direction"]
|
||||
else None
|
||||
)
|
||||
self.stops.extend(Stop(stop) for stop in data["Stops"]["Stop"])
|
||||
self.messages = []
|
||||
self.messages: List[Message] = []
|
||||
|
||||
if "Messages" in data:
|
||||
self.messages.extend(Message(message) for message in data["Messages"]["Message"])
|
||||
|
@@ -1,6 +1,7 @@
|
||||
from typing import Any, Mapping
|
||||
from datetime import timedelta
|
||||
from typing import Any, List, Mapping, Union
|
||||
|
||||
from isodate import parse_duration
|
||||
from isodate import Duration, parse_duration
|
||||
|
||||
from pyrmv.classes.gis import Gis
|
||||
from pyrmv.classes.message import Message
|
||||
@@ -11,19 +12,19 @@ class Leg:
|
||||
"""Trip leg object."""
|
||||
|
||||
def __init__(self, data: Mapping[str, Any]):
|
||||
self.origin = StopTrip(data["Origin"])
|
||||
self.destination = StopTrip(data["Destination"])
|
||||
self.origin: StopTrip = StopTrip(data["Origin"])
|
||||
self.destination: StopTrip = StopTrip(data["Destination"])
|
||||
self.gis = (
|
||||
None if "GisRef" not in data else Gis(data["GisRef"]["ref"], data["GisRoute"])
|
||||
)
|
||||
self.messages = []
|
||||
self.index = data["idx"]
|
||||
self.name = data["name"]
|
||||
self.type = data["type"]
|
||||
self.direction = data.get("direction")
|
||||
self.number = data.get("number")
|
||||
self.duration = parse_duration(data["duration"])
|
||||
self.distance = data.get("dist")
|
||||
self.messages: List[Message] = []
|
||||
self.index: Union[int, None] = data.get("idx")
|
||||
self.name: str = data["name"]
|
||||
self.type: Union[str, None] = data.get("type")
|
||||
self.direction: Union[str, None] = data.get("direction")
|
||||
self.number: Union[str, None] = data.get("number")
|
||||
self.duration: Union[Duration, timedelta] = parse_duration(data["duration"])
|
||||
self.distance: Union[int, None] = data.get("dist")
|
||||
|
||||
if "Messages" in data:
|
||||
self.messages.extend(Message(message) for message in data["Messages"]["Message"])
|
||||
|
@@ -1,7 +1,7 @@
|
||||
from datetime import datetime
|
||||
from typing import Any, Mapping
|
||||
from datetime import datetime, timedelta
|
||||
from typing import Any, List, Mapping, Union
|
||||
|
||||
from isodate import parse_duration
|
||||
from isodate import Duration, parse_duration
|
||||
|
||||
from pyrmv.classes.stop import Stop
|
||||
|
||||
@@ -10,8 +10,8 @@ class Url:
|
||||
"""Traffic message channel url object."""
|
||||
|
||||
def __init__(self, data: Mapping[str, Any]) -> None:
|
||||
self.name = data["name"]
|
||||
self.url = data["url"]
|
||||
self.name: str = data["name"]
|
||||
self.url: str = data["url"]
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.name}: {self.url}"
|
||||
@@ -21,51 +21,84 @@ class Channel:
|
||||
"""Traffic message channel object."""
|
||||
|
||||
def __init__(self, data: Mapping[str, Any]) -> None:
|
||||
self.name = data["name"]
|
||||
self.name: str = data["name"]
|
||||
url = []
|
||||
url.extend(Url(link) for link in url)
|
||||
self.url = url
|
||||
self.time_start = datetime.strptime(data["validFromTime"], "%H:%M:%S")
|
||||
self.date_start = datetime.strptime(data["validFromDate"], "%Y-%m-%d")
|
||||
self.time_end = datetime.strptime(data["validToTime"], "%H:%M:%S")
|
||||
self.date_end = datetime.strptime(data["validToDate"], "%Y-%m-%d")
|
||||
self.url: List[Url] = url
|
||||
self.time_start: Union[datetime, None] = (
|
||||
None
|
||||
if "validFromDate" not in data
|
||||
else datetime.strptime(
|
||||
f"{data['validFromDate']} {data['validFromTime']}", "%Y-%m-%d %H:%M:%S"
|
||||
)
|
||||
)
|
||||
self.time_end: Union[datetime, None] = (
|
||||
None
|
||||
if "validToDate" not in data
|
||||
else datetime.strptime(
|
||||
f"{data['validToDate']} {data['validToTime']}", "%Y-%m-%d %H:%M:%S"
|
||||
)
|
||||
)
|
||||
|
||||
def __str__(self) -> str:
|
||||
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} until {self.time_end}"
|
||||
|
||||
|
||||
class Message:
|
||||
"""Traffic message object."""
|
||||
|
||||
def __init__(self, data: Mapping[str, Any]) -> None:
|
||||
self.affected_stops = []
|
||||
self.valid_from_stop = (
|
||||
self.affected_stops: List[Stop] = []
|
||||
self.valid_from_stop: Union[Stop, None] = (
|
||||
None if "validFromStop" not in data else Stop(data["validFromStop"])
|
||||
)
|
||||
self.valid_to_stop = None if "validToStop" not in data else Stop(data["validToStop"])
|
||||
self.channels = []
|
||||
self.valid_to_stop: Union[Stop, None] = (
|
||||
None if "validToStop" not in data else Stop(data["validToStop"])
|
||||
)
|
||||
self.channels: Union[Channel, None] = []
|
||||
self.channels.extend(Channel(channel) for channel in data["channel"])
|
||||
self.id = data["id"]
|
||||
self.active = data["act"]
|
||||
self.head = data["head"]
|
||||
self.lead = data["lead"]
|
||||
self.text = data["text"]
|
||||
self.company = data["company"]
|
||||
self.category = data["category"]
|
||||
self.priority = None if "priority" not in data else data["priority"]
|
||||
self.products = data["products"]
|
||||
self.icon = data["icon"]
|
||||
self.time_start = datetime.strptime(data["sTime"], "%H:%M:%S")
|
||||
self.date_start = datetime.strptime(data["sDate"], "%Y-%m-%d")
|
||||
self.time_end = datetime.strptime(data["eTime"], "%H:%M:%S")
|
||||
self.date_end = datetime.strptime(data["eDate"], "%Y-%m-%d")
|
||||
self.date_start_alt = data["altStart"]
|
||||
self.date_end_alt = data["altEnd"]
|
||||
self.time_modified = datetime.strptime(data["modTime"], "%H:%M:%S")
|
||||
self.date_modified = datetime.strptime(data["modDate"], "%Y-%m-%d")
|
||||
self.daily_start = datetime.strptime(data["dailyStartingAt"], "%H:%M:%S")
|
||||
self.daily_duration = parse_duration(data["dailyDuration"])
|
||||
self.base_type = data["baseType"] if "baseType" in data else None
|
||||
self.id: str = data["id"]
|
||||
self.active: bool = data["act"]
|
||||
self.head: str = data["head"]
|
||||
self.lead: str = data["lead"]
|
||||
self.text: str = data["text"]
|
||||
self.company: Union[str, None] = data.get("company")
|
||||
self.category: Union[str, None] = data.get("category")
|
||||
self.priority: Union[int, None] = data.get("priority")
|
||||
self.products: int = data["products"]
|
||||
self.icon: Mapping[str, Any] = data["icon"]
|
||||
self.time_start: Union[datetime, None] = (
|
||||
None
|
||||
if "validFromDate" not in data or "validFromTime" not in data
|
||||
else datetime.strptime(
|
||||
f"{data['validFromDate']} {data['validFromTime']}", "%Y-%m-%d %H:%M:%S"
|
||||
)
|
||||
)
|
||||
self.time_end: Union[datetime, None] = (
|
||||
None
|
||||
if "validToDate" not in data or "validToTime" not in data
|
||||
else datetime.strptime(
|
||||
f"{data['validToDate']} {data['validToTime']}", "%Y-%m-%d %H:%M:%S"
|
||||
)
|
||||
)
|
||||
self.date_start_alt: str = data["altStart"]
|
||||
self.date_end_alt: str = data["altEnd"]
|
||||
self.time_modified: Union[datetime, None] = (
|
||||
None
|
||||
if "modDate" not in data or "modTime" not in data
|
||||
else datetime.strptime(
|
||||
f"{data['modDate']} {data['modTime']}", "%Y-%m-%d %H:%M:%S"
|
||||
)
|
||||
)
|
||||
self.daily_start: Union[datetime, None] = (
|
||||
None
|
||||
if "dailyStartingAt" not in data
|
||||
else datetime.strptime(data["dailyStartingAt"], "%H:%M:%S")
|
||||
)
|
||||
self.daily_duration: Union[Duration, timedelta] = parse_duration(
|
||||
data["dailyDuration"]
|
||||
)
|
||||
self.base_type: Union[str, None] = data.get("baseType")
|
||||
|
||||
if "affectedStops" in data:
|
||||
self.affected_stops.extend(
|
||||
@@ -73,4 +106,4 @@ class Message:
|
||||
)
|
||||
|
||||
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} until {self.time_end}: {self.head} - {self.lead}"
|
||||
|
@@ -1,19 +1,20 @@
|
||||
from datetime import datetime
|
||||
from typing import Union
|
||||
|
||||
|
||||
class Stop:
|
||||
"""Stop object."""
|
||||
|
||||
def __init__(self, data: dict):
|
||||
self.name = data["name"]
|
||||
self.id = data["id"]
|
||||
self.ext_id = data.get("extId")
|
||||
self.description = data.get("description")
|
||||
self.lon = data["lon"]
|
||||
self.lat = data["lat"]
|
||||
self.route_index = data.get("routeIdx")
|
||||
self.track_arrival = data.get("arrTrack")
|
||||
self.track_departure = data.get("depTrack")
|
||||
self.name: str = data["name"]
|
||||
self.id: str = data["id"]
|
||||
self.ext_id: Union[str, None] = data.get("extId")
|
||||
self.description: Union[str, None] = data.get("description")
|
||||
self.lon: float = data["lon"]
|
||||
self.lat: float = data["lat"]
|
||||
self.route_index: Union[int, None] = data.get("routeIdx")
|
||||
self.track_arrival: Union[str, None] = data.get("arrTrack")
|
||||
self.track_departure: Union[str, None] = data.get("depTrack")
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"Stop {self.name} at {self.lon}, {self.lat}"
|
||||
@@ -23,10 +24,11 @@ class StopTrip(Stop):
|
||||
"""Trip stop object. It's like a Stop object, but with a date and time."""
|
||||
|
||||
def __init__(self, data: dict):
|
||||
self.type = data["type"]
|
||||
self.date = datetime.strptime(data["date"], "%Y-%m-%d")
|
||||
self.time = datetime.strptime(data["time"], "%H:%M:%S")
|
||||
self.type: str = data["type"]
|
||||
self.time: datetime = datetime.strptime(
|
||||
f"{data['date']} {data['time']}", "%Y-%m-%d %H:%M:%S"
|
||||
)
|
||||
super().__init__(data)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"Stop {self.name} at {self.lon}, {self.lat} at {self.time.time()} {self.date.date()}"
|
||||
return f"Stop {self.name} at {self.lon}, {self.lat} at {self.time.time()}"
|
||||
|
@@ -1,4 +1,7 @@
|
||||
from isodate import parse_duration
|
||||
from datetime import timedelta
|
||||
from typing import List, Union
|
||||
|
||||
from isodate import Duration, parse_duration
|
||||
|
||||
from pyrmv.classes.leg import Leg
|
||||
from pyrmv.classes.stop import StopTrip
|
||||
@@ -8,21 +11,20 @@ class Trip:
|
||||
"""Trip object."""
|
||||
|
||||
def __init__(self, data: dict):
|
||||
self.raw_data = data
|
||||
self.origin = StopTrip(data["Origin"])
|
||||
self.destination = StopTrip(data["Destination"])
|
||||
self.legs = []
|
||||
self.origin: StopTrip = StopTrip(data["Origin"])
|
||||
self.destination: StopTrip = StopTrip(data["Destination"])
|
||||
self.legs: List[Leg] = []
|
||||
self.legs.extend(Leg(leg) for leg in data["LegList"]["Leg"])
|
||||
self.calculation = data["calculation"]
|
||||
self.index = data["idx"]
|
||||
self.id = data["tripId"]
|
||||
self.ctx_recon = data["ctxRecon"]
|
||||
self.duration = parse_duration(data["duration"])
|
||||
self.real_time_duration = (
|
||||
self.calculation: str = data["calculation"]
|
||||
self.index: int = data["idx"]
|
||||
self.id: str = data["tripId"]
|
||||
self.ctx_recon: str = data["ctxRecon"]
|
||||
self.duration: Union[Duration, timedelta] = parse_duration(data["duration"])
|
||||
self.real_time_duration: Union[Duration, timedelta] = (
|
||||
None if "rtDuration" not in data else parse_duration(data["rtDuration"])
|
||||
)
|
||||
self.checksum = data["checksum"]
|
||||
self.transfer_count = data.get("transferCount", 0)
|
||||
self.checksum: str = data["checksum"]
|
||||
self.transfer_count: int = data.get("transferCount", 0)
|
||||
|
||||
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"
|
||||
|
Reference in New Issue
Block a user