Cleaning up the code - renaming routes to trains as it makes more sense (each isntance is an instance of an individual train)

Reworking the MTA to be ready for use by people other than me.
This commit is contained in:
Lucas
2022-02-25 18:39:17 -05:00
parent 9919eed55b
commit e12079fbde
7 changed files with 89 additions and 82 deletions

View File

@@ -1,18 +1,18 @@
from time import time
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["arrival"]["time"], obj["departure"]["time"], obj["stop_id"])
return Stop( obj["stop_id"], obj["arrival"]["time"], obj["departure"]["time"])
return None
class Stop(object):
def __init__(self, arrival_time, departure_time, stop_id):
def __init__(self, id, arrival_time, departure_time, ):
self.id = id
self.arrival_time = arrival_time
self.departure_time = departure_time
self.stop_id = stop_id
def arrival_minutes(self):
return trunc(((datetime.fromtimestamp(self.arrival_time) - datetime.now()).total_seconds()) / 60)
@@ -21,4 +21,4 @@ class Stop(object):
now = datetime.now()
time = datetime.fromtimestamp(self.arrival_time)
time_minutes = trunc(((time - now).total_seconds()) / 60)
return f"arr:{time_minutes}|dep:{self.departure_time}|stop_id:{self.stop_id}"
return f"stop_id:{self.id}| arr:{time_minutes}| dep:{self.departure_time}"