PythonRMV/src/pyrmv/classes/stop.py

33 lines
1.0 KiB
Python
Raw Normal View History

2022-09-24 12:40:38 +03:00
from datetime import datetime
2022-09-23 23:58:45 +03:00
class Stop:
"""Stop object."""
2022-09-24 13:08:43 +03:00
def __init__(self, data: dict):
2022-09-23 23:58:45 +03:00
self.name = data["name"]
self.id = data["id"]
self.ext_id = data.get("extId")
self.description = data.get("description")
2022-09-23 23:58:45 +03:00
self.lon = data["lon"]
self.lat = data["lat"]
self.route_index = data.get("routeIdx")
self.track_arrival = data.get("arrTrack")
self.track_departure = 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}"
2022-09-23 23:58:45 +03:00
class StopTrip(Stop):
"""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):
self.type = data["type"]
2022-09-24 12:40:38 +03:00
self.date = datetime.strptime(data["date"], "%Y-%m-%d")
self.time = datetime.strptime(data["time"], "%H:%M:%S")
2022-09-23 23:58:45 +03:00
super().__init__(data)
def __str__(self) -> str:
return f"Stop {self.name} at {self.lon}, {self.lat} at {self.time.time()} {self.date.date()}"