Compare commits

...

3 Commits

Author SHA1 Message Date
651d709e66 rtMode argument now works flawlessly 2022-10-05 13:51:04 +02:00
93240ffcca Small docstring changes 2022-10-05 13:50:44 +02:00
65349e14b2 Board methods WIP 2022-10-05 13:50:26 +02:00
10 changed files with 191 additions and 10 deletions

2
pyrmv/classes/Board.py Normal file

@ -0,0 +1,2 @@
class Board():
pass

44
pyrmv/enums/board_type.py Normal file

@ -0,0 +1,44 @@
from enum import auto
from .auto_name import AutoName
class BoardArrivalType(AutoName):
"""Enumeration used to declare types of arrival board.
* ARR - Arrival board as configured in HAFAS
* ARR_EQUIVS - Arrival board with all journeys at any masts and equivalent stops
* ARR_MAST - Arrival board at mast
* ARR_STATION - Arrival board with all journeys at any masts of the requested station
"""
ARR = auto()
"Arrival board as configured in HAFAS"
ARR_EQUIVS = auto()
"Arrival board with all journeys at any masts and equivalent stops"
ARR_MAST = auto()
"Arrival board at mast"
ARR_STATION = auto()
"Arrival board with all journeys at any masts of the requested station"
class BoardDepartureType(AutoName):
"""Enumeration used to declare types of departure board.
* DEP - Departure board as configured in HAFAS
* DEP_EQUIVS - Departure board with all journeys at any masts and equivalent stops
* DEP_MAST - Departure board at mast
* DEP_STATION - Departure board with all journeys at any masts of the requested station
"""
DEP = auto()
"Departure board as configured in HAFAS"
DEP_EQUIVS = auto()
"Departure board with all journeys at any masts and equivalent stops"
DEP_MAST = auto()
"Departure board at mast"
DEP_STATION = auto()
"Departure board with all journeys at any masts of the requested station"

@ -1,5 +1,65 @@
from datetime import datetime, timedelta
from typing import Union
from pyrmv.classes.Board import Board
from pyrmv.classes.Stop import Stop, StopTrip
from pyrmv.enums.board_type import BoardArrivalType
from pyrmv.errors.not_ready import NotReadyYetError from pyrmv.errors.not_ready import NotReadyYetError
from pyrmv.raw import board_arrival as raw_board_arrival
from pyrmv.utility.find_exception import find_exception
def board_arrival(
access_id: str,
id: str = None,
id_ext: str = None,
direction: Union[str, Stop, StopTrip] = None,
date: Union[str, datetime] = None,
time: Union[str, datetime] = None,
duration: Union[int, timedelta] = 60,
journeys_max: int = -1,
operators: Union[str, list] = None,
lines: Union[str, list] = None,
passlist: bool = False,
board_type: Union[BoardArrivalType.ARR, BoardArrivalType.ARR_EQUIVS, BoardArrivalType.ARR_MAST, BoardArrivalType.ARR_STATION] = BoardArrivalType.ARR,
) -> Board:
"""Method returns a board with arriving transport.
def board_arrival(): More detailed request is available as `raw.board_arrival()`, however returns `dict` instead of `Board`.
raise NotReadyYetError()
### Args:
* access_id (`str`): Access ID for identifying the requesting client. Get your key on [RMV website](https://opendata.rmv.de/site/start.html).
* 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`.
* 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`.
### Returns:
* Board: Instance of Board object.
"""
board_raw = raw_board_arrival(
accessId=access_id,
id=id,
extId=id_ext,
direction=direction,
date=date,
time=time,
duration=duration,
maxJourneys=journeys_max,
operators=operators,
lines=lines,
passlist=passlist,
boardType=board_type.code
)
find_exception(board_raw)
raise NotReadyYetError()
# return Board(board_raw)

@ -1,5 +1,65 @@
from datetime import datetime, timedelta
from typing import Union
from pyrmv.classes.Board import Board
from pyrmv.classes.Stop import Stop, StopTrip
from pyrmv.enums.board_type import BoardDepartureType
from pyrmv.errors.not_ready import NotReadyYetError from pyrmv.errors.not_ready import NotReadyYetError
from pyrmv.raw import board_departure as raw_board_departure
from pyrmv.utility.find_exception import find_exception
def board_departure(
access_id: str,
id: str = None,
id_ext: str = None,
direction: Union[str, Stop, StopTrip] = None,
date: Union[str, datetime] = None,
time: Union[str, datetime] = None,
duration: Union[int, timedelta] = 60,
journeys_max: int = -1,
operators: Union[str, list] = None,
lines: Union[str, list] = None,
passlist: bool = False,
board_type: Union[BoardDepartureType.DEP, BoardDepartureType.DEP_EQUIVS, BoardDepartureType.DEP_MAST, BoardDepartureType.DEP_STATION] = BoardDepartureType.DEP,
) -> Board:
"""Method returns a board with departing transport.
def board_departure(): More detailed request is available as `raw.board_departure()`, however returns `dict` instead of `Board`.
raise NotReadyYetError()
### Args:
* access_id (`str`): Access ID for identifying the requesting client. Get your key on [RMV website](https://opendata.rmv.de/site/start.html).
* 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`.
* 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`.
### Returns:
* Board: Instance of Board object.
"""
board_raw = raw_board_departure(
accessId=access_id,
id=id,
extId=id_ext,
direction=direction,
date=date,
time=time,
duration=duration,
maxJourneys=journeys_max,
operators=operators,
lines=lines,
passlist=passlist,
boardType=board_type.code
)
find_exception(board_raw)
raise NotReadyYetError()
# return Board(board_raw)

@ -26,7 +26,7 @@ def stop_by_coords(
"""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.
More detailed request is available as raw.stop_by_coords(), however returns dict instead of List[Stop]. More detailed request is available as `raw.stop_by_coords()`, however returns `dict` instead of `List[Stop]`.
### Args: ### Args:
* access_id (`str`): Access ID for identifying the requesting client. Get your key on [RMV website](https://opendata.rmv.de/site/start.html). * access_id (`str`): Access ID for identifying the requesting client. Get your key on [RMV website](https://opendata.rmv.de/site/start.html).

@ -32,7 +32,7 @@ def stop_by_name(
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,
points of interest and addresses. points of interest and addresses.
More detailed request is available as raw.stop_by_name(), however returns dict instead of List[Stop]. More detailed request is available as `raw.stop_by_name()`, however returns `dict` instead of `List[Stop]`.
### Args: ### Args:
* access_id (`str`): Access ID for identifying the requesting client. Get your key on [RMV website](https://opendata.rmv.de/site/start.html). * access_id (`str`): Access ID for identifying the requesting client. Get your key on [RMV website](https://opendata.rmv.de/site/start.html).

@ -77,7 +77,7 @@ def trip_find(
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.
More detailed request is available as raw.trip_find(), however returns dict instead of List[Trip]. More detailed request is available as `raw.trip_find()`, however returns `dict` instead of `List[Trip]`.
### Args: ### Args:
* access_id (`str`): Access ID for identifying the requesting client. Get your key on [RMV website](https://opendata.rmv.de/site/start.html). * access_id (`str`): Access ID for identifying the requesting client. Get your key on [RMV website](https://opendata.rmv.de/site/start.html).
@ -131,7 +131,7 @@ def trip_find(
if real_time_mode == None: if real_time_mode == None:
real_time_mode = None real_time_mode = None
else: else:
real_time_mode = (real_time_mode.code).upper() real_time_mode = real_time_mode.code
trips = [] trips = []
trips_raw = raw_trip_find( trips_raw = raw_trip_find(

@ -1,5 +1,5 @@
from requests import get from requests import get
from datetime import datetime from datetime import datetime, timedelta
from typing import Union from typing import Union
from xmltodict import parse as xmlparse from xmltodict import parse as xmlparse
@ -78,6 +78,12 @@ def board_arrival(accessId: str,
payload[str(var)] = val.strftime("%H:%M") payload[str(var)] = val.strftime("%H:%M")
else: else:
payload[str(var)] = val payload[str(var)] = val
elif str(var) == "duration":
if val != None:
if isinstance(val, timedelta):
payload[str(var)] = val.minutes
else:
payload[str(var)] = val
elif str(var) == "boardType": elif str(var) == "boardType":
if val != None: if val != None:
payload["type"] = val payload["type"] = val

@ -1,5 +1,5 @@
from datetime import datetime
from requests import get from requests import get
from datetime import datetime, timedelta
from typing import Union from typing import Union
from xmltodict import parse as xmlparse from xmltodict import parse as xmlparse
@ -79,6 +79,12 @@ def board_departure(accessId: str,
payload[str(var)] = val.strftime("%H:%M") payload[str(var)] = val.strftime("%H:%M")
else: else:
payload[str(var)] = val payload[str(var)] = val
elif str(var) == "duration":
if val != None:
if isinstance(val, timedelta):
payload[str(var)] = val.minutes
else:
payload[str(var)] = val
elif str(var) == "boardType": elif str(var) == "boardType":
if val != None: if val != None:
payload["type"] = val payload["type"] = val

@ -239,6 +239,9 @@ def trip_find(accessId: str,
payload[str(var)] = val.strftime("%H:%M") payload[str(var)] = val.strftime("%H:%M")
else: else:
payload[str(var)] = val payload[str(var)] = val
elif str(var) == "rtMode":
if val != None:
payload["rtMode"] = val.upper()
elif str(var) not in ["json", "headers", "payload"]: elif str(var) not in ["json", "headers", "payload"]:
if val != None: if val != None:
payload[str(var)] = val payload[str(var)] = val