Major classes changes
This commit is contained in:
parent
1770695067
commit
660c9644f9
@ -1,9 +1,12 @@
|
|||||||
from pyrmv.classes.Gis import Gis
|
from pyrmv.classes.Gis import Gis
|
||||||
|
from pyrmv.classes.Message import Message
|
||||||
from pyrmv.classes.Stop import StopTrip
|
from pyrmv.classes.Stop import StopTrip
|
||||||
from isodate import parse_duration
|
from isodate import parse_duration
|
||||||
|
|
||||||
class Leg():
|
class Leg():
|
||||||
|
|
||||||
def __init__(self, data: dict):
|
def __init__(self, data: dict):
|
||||||
|
|
||||||
self.origin = StopTrip(data["Origin"])
|
self.origin = StopTrip(data["Origin"])
|
||||||
self.destination = StopTrip(data["Destination"])
|
self.destination = StopTrip(data["Destination"])
|
||||||
if "GisRef" in data:
|
if "GisRef" in data:
|
||||||
@ -13,7 +16,27 @@ class Leg():
|
|||||||
self.index = data["idx"]
|
self.index = data["idx"]
|
||||||
self.name = data["name"]
|
self.name = data["name"]
|
||||||
self.type = data["type"]
|
self.type = data["type"]
|
||||||
|
|
||||||
|
if "direction" in data:
|
||||||
|
self.direction = data["direction"]
|
||||||
|
else:
|
||||||
|
self.direction = None
|
||||||
|
|
||||||
|
if "Messages" in data:
|
||||||
|
messages = []
|
||||||
|
for message in data["Messages"]["Message"]:
|
||||||
|
messages.append(Message(message))
|
||||||
|
self.messages = messages
|
||||||
|
else:
|
||||||
|
self.messages = None
|
||||||
|
|
||||||
|
if "number" in data:
|
||||||
|
self.number = data["number"]
|
||||||
|
else:
|
||||||
|
self.number = None
|
||||||
|
|
||||||
self.duration = parse_duration(data["duration"])
|
self.duration = parse_duration(data["duration"])
|
||||||
|
|
||||||
if "dist" in data:
|
if "dist" in data:
|
||||||
self.distance = data["dist"]
|
self.distance = data["dist"]
|
||||||
else:
|
else:
|
||||||
|
75
pyrmv/classes/Message.py
Normal file
75
pyrmv/classes/Message.py
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
from pyrmv.classes.Stop import Stop
|
||||||
|
from datetime import datetime
|
||||||
|
from isodate import parse_duration
|
||||||
|
|
||||||
|
class Url():
|
||||||
|
|
||||||
|
def __init__(self, data: dict) -> None:
|
||||||
|
self.name = data["name"]
|
||||||
|
self.url = data["url"]
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
return f"{self.name}: {self.url}"
|
||||||
|
|
||||||
|
class Channel():
|
||||||
|
|
||||||
|
def __init__(self, data: dict) -> None:
|
||||||
|
self.name = data["name"]
|
||||||
|
url = []
|
||||||
|
for link in url:
|
||||||
|
url.append(Url(link))
|
||||||
|
self.url = url
|
||||||
|
self.time_start = datetime.strptime(data["validFromTime"], "%H:%M:%S")
|
||||||
|
self.date_start = datetime.strptime(data["validFromDate"], "%Y-%m-%d")
|
||||||
|
self.time_end = datetime.strptime(data["validToTime"], "%H:%M:%S")
|
||||||
|
self.date_end = datetime.strptime(data["validToDate"], "%Y-%m-%d")
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
return f"{self.name}: from {self.time_start} {self.date_start} until {self.time_end} {self.date_end}"
|
||||||
|
|
||||||
|
|
||||||
|
class Message():
|
||||||
|
|
||||||
|
def __init__(self, data: dict) -> None:
|
||||||
|
|
||||||
|
affected_stops = []
|
||||||
|
for stop in data["affectedStops"]["StopLocation"]:
|
||||||
|
affected_stops.append(Stop(stop))
|
||||||
|
self.affected_stops = affected_stops
|
||||||
|
|
||||||
|
self.valid_from_stop = Stop(data["validFromStop"])
|
||||||
|
self.valid_to_stop = Stop(data["validToStop"])
|
||||||
|
|
||||||
|
channels = []
|
||||||
|
for channel in data["channel"]:
|
||||||
|
channels.append(Channel(channel))
|
||||||
|
self.channels = channels
|
||||||
|
|
||||||
|
self.id = data["id"]
|
||||||
|
self.active = data["act"]
|
||||||
|
self.head = data["head"]
|
||||||
|
self.lead = data["lead"]
|
||||||
|
self.text = data["text"]
|
||||||
|
self.company = data["company"]
|
||||||
|
self.category = data["category"]
|
||||||
|
self.priority = data["priority"]
|
||||||
|
self.products = data["products"]
|
||||||
|
self.icon = data["icon"]
|
||||||
|
self.time_start = datetime.strptime(data["sTime"], "%H:%M:%S")
|
||||||
|
self.date_start = datetime.strptime(data["sDate"], "%Y-%m-%d")
|
||||||
|
self.time_end = datetime.strptime(data["eTime"], "%H:%M:%S")
|
||||||
|
self.date_end = datetime.strptime(data["eDate"], "%Y-%m-%d")
|
||||||
|
self.date_start_alt = data["altStart"]
|
||||||
|
self.date_end_alt = data["altEnd"]
|
||||||
|
self.time_modified = datetime.strptime(data["modTime"], "%H:%M:%S")
|
||||||
|
self.date_modified = datetime.strptime(data["modDate"], "%Y-%m-%d")
|
||||||
|
self.daily_start = datetime.strptime(data["dailyStartingAt"], "%H:%M:%S")
|
||||||
|
self.daily_duration = parse_duration(data["dailyDuration"])
|
||||||
|
|
||||||
|
if "baseType" in data:
|
||||||
|
self.base_type = data["baseType"]
|
||||||
|
else:
|
||||||
|
self.base_type = None
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
return f"{self.base_type} message with priority {self.products} valid from {self.time_start.time()} {self.date_start.date()} until {self.time_end.time()} {self.date_end.date()}: {self.head} - {self.lead}"
|
@ -1,7 +1,8 @@
|
|||||||
from time import strptime
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
class Stop():
|
class Stop():
|
||||||
|
|
||||||
def __init__(self, data: dict):
|
def __init__(self, data: dict):
|
||||||
self.name = data["name"]
|
self.name = data["name"]
|
||||||
self.id = data["id"]
|
self.id = data["id"]
|
||||||
@ -12,15 +13,29 @@ class Stop():
|
|||||||
self.lon = data["lon"]
|
self.lon = data["lon"]
|
||||||
self.lat = data["lat"]
|
self.lat = data["lat"]
|
||||||
|
|
||||||
|
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}"
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return f"Stop {self.name} at {self.lon}, {self.lat}"
|
return f"Stop {self.name} at {self.lon}, {self.lat}"
|
||||||
|
|
||||||
class StopTrip(Stop):
|
class StopTrip(Stop):
|
||||||
|
|
||||||
def __init__(self, data: dict):
|
def __init__(self, data: dict):
|
||||||
self.type = data["type"]
|
self.type = data["type"]
|
||||||
self.date = strptime(data["date"], "%Y-%m-%d")
|
self.date = datetime.strptime(data["date"], "%Y-%m-%d")
|
||||||
self.time = strptime(data["time"], "%H:%M:%S")
|
self.time = datetime.strptime(data["time"], "%H:%M:%S")
|
||||||
super().__init__(data)
|
super().__init__(data)
|
||||||
|
|
||||||
|
def get_id(self) -> str:
|
||||||
|
return super().get_id()
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return f"Stop {self.name} at {self.lon}, {self.lat} at {self.time} {self.date}"
|
return f"Stop {self.name} at {self.lon}, {self.lat} at {self.time} {self.date}"
|
Loading…
Reference in New Issue
Block a user