moving to static methods for creators.

This commit is contained in:
Lucas
2022-03-30 22:57:54 -04:00
parent e12079fbde
commit 30cbe70d7b
3 changed files with 22 additions and 20 deletions

View File

@@ -2,10 +2,7 @@
from datetime import datetime
from math import trunc
def get_stop_from_dict(obj):
if "arrival" in obj and "departure" in obj and "stop_id" in obj:
return Stop( obj["stop_id"], obj["arrival"]["time"], obj["departure"]["time"])
return None
class Stop(object):
@@ -22,3 +19,9 @@ class Stop(object):
time = datetime.fromtimestamp(self.arrival_time)
time_minutes = trunc(((time - now).total_seconds()) / 60)
return f"stop_id:{self.id}| arr:{time_minutes}| dep:{self.departure_time}"
@staticmethod
def get_stop_from_dict(obj):
if "arrival" in obj and "departure" in obj and "stop_id" in obj:
return Stop(obj["stop_id"], obj["arrival"]["time"], obj["departure"]["time"])
return None