Added retrieve_stops argument
This commit is contained in:
parent
80a788933d
commit
1b863c55f1
@ -3,7 +3,7 @@ from pyrmv.classes.Message import Message
|
|||||||
|
|
||||||
class LineArrival():
|
class LineArrival():
|
||||||
|
|
||||||
def __init__(self, data, client):
|
def __init__(self, data, 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 = []
|
||||||
@ -14,6 +14,10 @@ class LineArrival():
|
|||||||
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)
|
||||||
|
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")
|
||||||
@ -28,7 +32,7 @@ class LineArrival():
|
|||||||
|
|
||||||
class LineDeparture():
|
class LineDeparture():
|
||||||
|
|
||||||
def __init__(self, data, client):
|
def __init__(self, data, 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 = []
|
||||||
@ -39,7 +43,10 @@ class LineDeparture():
|
|||||||
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"]
|
||||||
self.stop = client.stop_by_id(self.stop_id)
|
if retrieve_stops:
|
||||||
|
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):
|
if ("rtTime" in data) and ("rtDate" in data):
|
||||||
@ -54,10 +61,10 @@ class LineDeparture():
|
|||||||
|
|
||||||
class BoardArrival(list):
|
class BoardArrival(list):
|
||||||
|
|
||||||
def __init__(self, data: dict, client):
|
def __init__(self, data: dict, client, retrieve_stops: bool = True):
|
||||||
super().__init__([])
|
super().__init__([])
|
||||||
for line in data["Arrival"]:
|
for line in data["Arrival"]:
|
||||||
self.append(LineArrival(line, client))
|
self.append(LineArrival(line, client, retrieve_stops=retrieve_stops))
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
lines = []
|
lines = []
|
||||||
@ -67,10 +74,10 @@ class BoardArrival(list):
|
|||||||
|
|
||||||
class BoardDeparture(list):
|
class BoardDeparture(list):
|
||||||
|
|
||||||
def __init__(self, data: dict, client):
|
def __init__(self, data: dict, client, retrieve_stops: bool = True):
|
||||||
super().__init__([])
|
super().__init__([])
|
||||||
for line in data["Departure"]:
|
for line in data["Departure"]:
|
||||||
self.append(LineDeparture(line, client))
|
self.append(LineDeparture(line, client, retrieve_stops=retrieve_stops))
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
lines = []
|
lines = []
|
||||||
|
@ -81,6 +81,7 @@ class Client():
|
|||||||
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[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.
|
||||||
|
|
||||||
@ -98,6 +99,7 @@ class Client():
|
|||||||
* 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`.
|
* 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`.
|
* 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 decrease number of requests made (good for low access_key rate limit). Defaults to `True`.
|
||||||
|
|
||||||
### Returns:
|
### Returns:
|
||||||
* BoardArrival: Instance of `BoardArrival` object.
|
* BoardArrival: Instance of `BoardArrival` object.
|
||||||
@ -123,7 +125,7 @@ class Client():
|
|||||||
|
|
||||||
find_exception(board_raw)
|
find_exception(board_raw)
|
||||||
|
|
||||||
return BoardArrival(board_raw, self)
|
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,
|
||||||
@ -137,6 +139,7 @@ class Client():
|
|||||||
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[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.
|
||||||
|
|
||||||
@ -154,6 +157,7 @@ class Client():
|
|||||||
* 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`.
|
* 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`.
|
* 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 decrease number of requests made (good for low access_key rate limit). Defaults to `True`.
|
||||||
|
|
||||||
### Returns:
|
### Returns:
|
||||||
* BoardDeparture: Instance of `BoardDeparture` object.
|
* BoardDeparture: Instance of `BoardDeparture` object.
|
||||||
@ -179,7 +183,7 @@ class Client():
|
|||||||
|
|
||||||
find_exception(board_raw)
|
find_exception(board_raw)
|
||||||
|
|
||||||
return BoardDeparture(board_raw, self)
|
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,
|
||||||
|
Loading…
Reference in New Issue
Block a user