feat: adding ruff linting support
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -123,3 +123,5 @@ venv.bak/
|
||||
.mypy_cache/
|
||||
.dmypy.json
|
||||
dmypy.jsons
|
||||
|
||||
.ruff_cache
|
||||
@@ -1,3 +0,0 @@
|
||||
from .mta import *
|
||||
from .train import *
|
||||
from .stop import *
|
||||
|
||||
@@ -52,10 +52,10 @@ class MTA(object):
|
||||
feed = gtfs_realtime_pb2.FeedMessage()
|
||||
feed.ParseFromString(r.content)
|
||||
subway_feed = protobuf_to_dict(feed)['entity']
|
||||
trains.extend([train for train in [Train.get_train_from_dict(train_dict) for train_dict in subway_feed] if train is not None])
|
||||
trains.extend([train for train in [Train.get_train_from_dict(train_dict) for train_dict in subway_feed] if
|
||||
train is not None])
|
||||
return trains
|
||||
|
||||
|
||||
@staticmethod
|
||||
def get_trains_for_routes(routes, trains):
|
||||
return [train for train in trains if train.route in routes]
|
||||
@@ -64,11 +64,8 @@ class MTA(object):
|
||||
def get_trains_for_route(route, trains):
|
||||
return MTA.get_trains_for_routes([route], trains)
|
||||
|
||||
|
||||
async def get_train_information(self):
|
||||
# Might need to not filter these trains.
|
||||
valid_trains = [train for train in await self.get_data() if True]
|
||||
# MTA.trains_arriving_at_stations(self.train_lines, self.station_ids, train, self.max_arrival_time)]
|
||||
return valid_trains
|
||||
|
||||
async def _get_updates(self):
|
||||
@@ -109,7 +106,8 @@ class MTA(object):
|
||||
for station_id in self.station_ids:
|
||||
line_first = {}
|
||||
for route in self.routes:
|
||||
valid_trains = [train.get_arrival_at(station_id) for train in MTA.get_trains_for_route(route, trains) if train.arriving_at_station_in_time(station_id, self.max_arrival_time)]
|
||||
valid_trains = [train.get_arrival_at(station_id) for train in MTA.get_trains_for_route(route, trains) if
|
||||
train.arriving_at_station_in_time(station_id, self.max_arrival_time)]
|
||||
if valid_trains:
|
||||
line_first[route] = valid_trains
|
||||
if line_first:
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
|
||||
from datetime import datetime
|
||||
from math import trunc
|
||||
|
||||
|
||||
|
||||
|
||||
class Stop(object):
|
||||
def __init__(self, id, arrival_time, departure_time, ):
|
||||
self.id = id
|
||||
|
||||
16
mta_test.py
16
mta_test.py
@@ -2,7 +2,7 @@ import os
|
||||
from dotenv import load_dotenv
|
||||
from mta_manager import MTA
|
||||
import threading
|
||||
import time
|
||||
|
||||
from time import sleep
|
||||
from pprint import pprint
|
||||
|
||||
@@ -15,13 +15,15 @@ mtaController = MTA(
|
||||
["127S", "127N", "A27N", "A27S"]
|
||||
)
|
||||
|
||||
|
||||
async def mta_callback(trains):
|
||||
print("We are inside of the call back now")
|
||||
print(len(trains))
|
||||
pprint([str(route) for route in trains])
|
||||
pprint(mtaController.get_time_arriving_at_stations(trains))
|
||||
|
||||
class threadWrapper(threading.Thread):
|
||||
|
||||
class Threadwrapper(threading.Thread):
|
||||
def __init__(self, run):
|
||||
threading.Thread.__init__(self)
|
||||
self.run = run
|
||||
@@ -29,21 +31,23 @@ class threadWrapper(threading.Thread):
|
||||
def run(self):
|
||||
self.run()
|
||||
|
||||
|
||||
def start_mta():
|
||||
mtaController.add_callback(mta_callback)
|
||||
mtaController.start_updates()
|
||||
|
||||
|
||||
def stop_mta():
|
||||
sleep(10)
|
||||
mtaController.stop_updates()
|
||||
|
||||
|
||||
threadLock = threading.Lock()
|
||||
threads = []
|
||||
|
||||
# Create new threads
|
||||
thread1 = threadWrapper(start_mta)
|
||||
thread2 = threadWrapper(stop_mta)
|
||||
|
||||
thread1 = Threadwrapper(start_mta)
|
||||
thread2 = Threadwrapper(stop_mta)
|
||||
|
||||
thread1.start()
|
||||
thread2.start()
|
||||
@@ -55,4 +59,4 @@ threads.append(thread2)
|
||||
# Wait for all threads to complete
|
||||
for t in threads:
|
||||
t.join()
|
||||
print ("Exiting Main Thread")
|
||||
print("Exiting Main Thread")
|
||||
|
||||
Reference in New Issue
Block a user