PythonRMV/pyrmv/classes/Stop.py

41 lines
1.1 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-09-24 12:40:38 +03:00
2022-09-23 23:58:45 +03:00
def __init__(self, data: dict):
self.name = data["name"]
self.id = data["id"]
if "extId" in data:
self.ext_id = data["extId"]
else:
self.ext_id = None
self.lon = data["lon"]
self.lat = data["lat"]
2022-09-24 12:40:38 +03:00
def get_id(self) -> str:
if self.id != None:
return self.id
elif self.ext_id != None:
return self.ext_id
elif self.name != None:
return self.name
else:
return f"{self.lon}, {self.lat}"
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-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)
2022-09-24 12:40:38 +03:00
def get_id(self) -> str:
return super().get_id()
2022-09-23 23:58:45 +03:00
def __str__(self) -> str:
return f"Stop {self.name} at {self.lon}, {self.lat} at {self.time.time()} {self.date.date()}"