From 7e4cde8762f3ef895f06832d3dfe10779e2ea458 Mon Sep 17 00:00:00 2001 From: profitroll Date: Wed, 5 Oct 2022 15:06:36 +0200 Subject: [PATCH] board_arrival and board_departure made --- pyrmv/classes/Board.py | 82 +++++++++++++++++++++++++++++--- pyrmv/methods/board_arrival.py | 4 +- pyrmv/methods/board_departure.py | 4 +- 3 files changed, 80 insertions(+), 10 deletions(-) diff --git a/pyrmv/classes/Board.py b/pyrmv/classes/Board.py index 5f6a16e..8bfda59 100644 --- a/pyrmv/classes/Board.py +++ b/pyrmv/classes/Board.py @@ -1,8 +1,78 @@ -class Board(): - pass +# from pyrmv.methods.journey_detail import journey_detail -class BoardArrival(Board): - pass +from datetime import datetime +from pyrmv.methods.stop_by_id import stop_by_id -class BoardDeparture(Board): - pass \ No newline at end of file + +class LineArrival(): + + def __init__(self, data, access_id: str): + # self.journey = journey_detail(line["JourneyDetailRef"]["ref"]) + 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 = stop_by_id(access_id, self.stop_id) + self.time = datetime.strptime(data["time"], "%H:%M:%S") + 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.origin = data["origin"] + + def __str__(self) -> str: + return f"{self.name} coming from {self.origin} at {self.time.time()} {self.date.date()}" + +class LineDeparture(): + + def __init__(self, data, access_id: str): + # self.journey = journey_detail(line["JourneyDetailRef"]["ref"]) + 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 = stop_by_id(access_id, self.stop_id) + self.time = datetime.strptime(data["time"], "%H:%M:%S") + 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.direction = data["direction"] + self.direction_flag = data["directionFlag"] + + def __str__(self) -> str: + return f"{self.name} heading {self.direction} at {self.time.time()} {self.date.date()}" + +class BoardArrival(list): + + def __init__(self, data: dict, access_id: str): + super().__init__([]) + for line in data["Arrival"]: + self.append(LineArrival(line, access_id)) + + def __str__(self) -> str: + lines = [] + for line in self: + lines.append(str(line)) + return "Arrival board\n" + "\n".join(lines) + +class BoardDeparture(list): + + def __init__(self, data: dict, access_id: str): + super().__init__([]) + for line in data["Departure"]: + self.append(LineDeparture(line, access_id)) + + def __str__(self) -> str: + lines = [] + for line in self: + lines.append(str(line)) + return "Departure board\n" + "\n".join(lines) \ No newline at end of file diff --git a/pyrmv/methods/board_arrival.py b/pyrmv/methods/board_arrival.py index bb29f9b..72db566 100644 --- a/pyrmv/methods/board_arrival.py +++ b/pyrmv/methods/board_arrival.py @@ -66,5 +66,5 @@ def board_arrival( find_exception(board_raw) - raise NotReadyYetError() - # return BoardArrival(board_raw) \ No newline at end of file + # raise NotReadyYetError() + return BoardArrival(board_raw, access_id) \ No newline at end of file diff --git a/pyrmv/methods/board_departure.py b/pyrmv/methods/board_departure.py index 88c694e..a8e4bf7 100644 --- a/pyrmv/methods/board_departure.py +++ b/pyrmv/methods/board_departure.py @@ -66,5 +66,5 @@ def board_departure( find_exception(board_raw) - raise NotReadyYetError() - # return BoardDeparture(board_raw) \ No newline at end of file + # raise NotReadyYetError() + return BoardDeparture(board_raw, access_id) \ No newline at end of file