2022-09-24 12:40:38 +03:00
|
|
|
from datetime import datetime
|
2023-11-27 22:44:17 +02:00
|
|
|
from typing import Union
|
2022-09-23 23:58:45 +03:00
|
|
|
|
|
|
|
|
2023-11-24 12:21:02 +02:00
|
|
|
class Stop:
|
|
|
|
"""Stop object."""
|
2022-09-24 13:08:43 +03:00
|
|
|
|
2023-11-24 12:21:02 +02:00
|
|
|
def __init__(self, data: dict):
|
2023-11-27 22:44:17 +02:00
|
|
|
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")
|
2022-10-06 12:36:08 +03:00
|
|
|
|
2022-09-23 23:58:45 +03:00
|
|
|
def __str__(self) -> str:
|
|
|
|
return f"Stop {self.name} at {self.lon}, {self.lat}"
|
|
|
|
|
2023-11-24 12:21:02 +02:00
|
|
|
|
2022-09-23 23:58:45 +03:00
|
|
|
class StopTrip(Stop):
|
2023-11-24 12:21:02 +02:00
|
|
|
"""Trip stop object. It's like a Stop object, but with a date and time."""
|
2022-09-24 12:40:38 +03:00
|
|
|
|
2022-09-23 23:58:45 +03:00
|
|
|
def __init__(self, data: dict):
|
2023-11-27 22:44:17 +02:00
|
|
|
self.type: str = data["type"]
|
|
|
|
self.time: datetime = datetime.strptime(
|
|
|
|
f"{data['date']} {data['time']}", "%Y-%m-%d %H:%M:%S"
|
|
|
|
)
|
2022-09-23 23:58:45 +03:00
|
|
|
super().__init__(data)
|
|
|
|
|
|
|
|
def __str__(self) -> str:
|
2023-11-27 22:44:17 +02:00
|
|
|
return f"Stop {self.name} at {self.lon}, {self.lat} at {self.time.time()}"
|