PythonRMV/pyrmv/classes/Board.py

79 lines
3.0 KiB
Python
Raw Normal View History

2022-10-05 16:06:36 +03:00
from datetime import datetime
2022-10-06 14:17:16 +03:00
from pyrmv.classes.Message import Message
2022-10-05 16:06:36 +03:00
class LineArrival():
2022-10-07 12:35:02 +03:00
def __init__(self, data, client):
self.journey = client.journey_detail(data["JourneyDetailRef"]["ref"])
2022-10-05 16:06:36 +03:00
self.status = data["JourneyStatus"]
2022-10-06 14:17:16 +03:00
self.messages = []
for message in data["Messages"]["Message"]:
self.messages.append(Message(message))
2022-10-05 16:06:36 +03:00
self.name = data["name"]
self.type = data["type"]
self.stop_name = data["stop"]
self.stop_id = data["stopid"]
self.stop_id_ext = data["stopExtId"]
2022-10-07 12:35:02 +03:00
self.stop = client.stop_by_id(self.stop_id)
2022-10-05 16:06:36 +03:00
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():
2022-10-07 12:35:02 +03:00
def __init__(self, data, client):
self.journey = client.journey_detail(data["JourneyDetailRef"]["ref"])
2022-10-05 16:06:36 +03:00
self.status = data["JourneyStatus"]
2022-10-06 14:17:16 +03:00
self.messages = []
for message in data["Messages"]["Message"]:
self.messages.append(Message(message))
2022-10-05 16:06:36 +03:00
self.name = data["name"]
self.type = data["type"]
self.stop_name = data["stop"]
self.stop_id = data["stopid"]
self.stop_id_ext = data["stopExtId"]
2022-10-07 12:35:02 +03:00
self.stop = client.stop_by_id(self.stop_id)
2022-10-05 16:06:36 +03:00
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):
2022-10-07 12:35:02 +03:00
def __init__(self, data: dict, client):
2022-10-05 16:06:36 +03:00
super().__init__([])
for line in data["Arrival"]:
2022-10-07 12:35:02 +03:00
self.append(LineArrival(line, client))
2022-10-05 16:06:36 +03:00
def __str__(self) -> str:
lines = []
for line in self:
lines.append(str(line))
return "Arrival board\n" + "\n".join(lines)
class BoardDeparture(list):
2022-10-07 12:35:02 +03:00
def __init__(self, data: dict, client):
2022-10-05 16:06:36 +03:00
super().__init__([])
for line in data["Departure"]:
2022-10-07 12:35:02 +03:00
self.append(LineDeparture(line, client))
2022-10-05 16:06:36 +03:00
def __str__(self) -> str:
lines = []
for line in self:
lines.append(str(line))
return "Departure board\n" + "\n".join(lines)