PythonRMV/src/pyrmv/classes/Stop.py

54 lines
1.4 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():
2022-10-05 13:17:51 +03:00
"""Stop object."""
2022-09-24 12:40:38 +03:00
2022-09-23 23:58:45 +03:00
def __init__(self, data: dict):
2022-09-24 13:08:43 +03:00
2022-09-23 23:58:45 +03:00
self.name = data["name"]
self.id = data["id"]
2022-10-06 12:36:08 +03:00
2022-09-23 23:58:45 +03:00
if "extId" in data:
self.ext_id = data["extId"]
else:
self.ext_id = None
2022-10-06 12:36:08 +03:00
2022-10-05 13:17:51 +03:00
if "description" in data:
self.description = data["description"]
else:
self.description = None
2022-10-06 12:36:08 +03:00
2022-09-23 23:58:45 +03:00
self.lon = data["lon"]
self.lat = data["lat"]
2022-10-06 12:36:08 +03:00
if "routeIdx" in data:
self.route_index = data["routeIdx"]
else:
self.route_index = None
if "arrTrack" in data:
self.track_arrival = data["arrTrack"]
else:
self.track_arrival = None
if "depTrack" in data:
self.track_departure = data["depTrack"]
else:
self.track_departure = None
2022-09-23 23:58:45 +03:00
def __str__(self) -> str:
return f"Stop {self.name} at {self.lon}, {self.lat}"
class StopTrip(Stop):
2022-10-05 13:17:51 +03: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):
2022-09-24 13:08:43 +03:00
2022-09-23 23:58:45 +03:00
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()}"