mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-03-15 12:24:29 +00:00
Improve adherence to python coding standards and clear up IDE static analysis warnings
This commit is contained in:
@@ -16,21 +16,21 @@ class SpotProvider:
|
||||
self.last_update_time = datetime.min.replace(tzinfo=pytz.UTC)
|
||||
self.last_spot_time = datetime.min.replace(tzinfo=pytz.UTC)
|
||||
self.status = "Not Started" if self.enabled else "Disabled"
|
||||
self.spots = None
|
||||
self.web_server = None
|
||||
self._spots = None
|
||||
self._web_server = None
|
||||
|
||||
def setup(self, spots, web_server):
|
||||
"""Set up the provider, e.g. giving it the spot list to work from"""
|
||||
|
||||
self.spots = spots
|
||||
self.web_server = web_server
|
||||
self._spots = spots
|
||||
self._web_server = web_server
|
||||
|
||||
def start(self):
|
||||
"""Start the provider. This should return immediately after spawning threads to access the remote resources"""
|
||||
|
||||
raise NotImplementedError("Subclasses must implement this method")
|
||||
|
||||
def submit_batch(self, spots):
|
||||
def _submit_batch(self, spots):
|
||||
"""Submit a batch of spots retrieved from the provider. Only spots that are newer than the last spot retrieved
|
||||
by this provider will be added to the spot list, to prevent duplications. Spots passing the check will also have
|
||||
their infer_missing() method called to complete their data set. This is called by the API-querying
|
||||
@@ -38,30 +38,30 @@ class SpotProvider:
|
||||
|
||||
# Sort the batch so that earliest ones go in first. This helps keep the ordering correct when spots are fired
|
||||
# off to SSE listeners.
|
||||
spots = sorted(spots, key=lambda spot: (spot.time if spot and spot.time else 0))
|
||||
spots = sorted(spots, key=lambda s: (s.time if s and s.time else 0))
|
||||
for spot in spots:
|
||||
if datetime.fromtimestamp(spot.time, pytz.UTC) > self.last_spot_time:
|
||||
# Fill in any blanks and add to the list
|
||||
spot.infer_missing()
|
||||
self.add_spot(spot)
|
||||
self._add_spot(spot)
|
||||
self.last_spot_time = datetime.fromtimestamp(max(map(lambda s: s.time, spots)), pytz.UTC)
|
||||
|
||||
def submit(self, spot):
|
||||
def _submit(self, spot):
|
||||
"""Submit a single spot retrieved from the provider. This will be added to the list regardless of its age. Spots
|
||||
passing the check will also have their infer_missing() method called to complete their data set. This is called by
|
||||
the data streaming subclasses, which can be relied upon not to re-provide old spots."""
|
||||
|
||||
# Fill in any blanks and add to the list
|
||||
spot.infer_missing()
|
||||
self.add_spot(spot)
|
||||
self._add_spot(spot)
|
||||
self.last_spot_time = datetime.fromtimestamp(spot.time, pytz.UTC)
|
||||
|
||||
def add_spot(self, spot):
|
||||
def _add_spot(self, spot):
|
||||
if not spot.expired():
|
||||
self.spots.add(spot.id, spot, expire=MAX_SPOT_AGE)
|
||||
self._spots.add(spot.id, spot, expire=MAX_SPOT_AGE)
|
||||
# Ping the web server in case we have any SSE connections that need to see this immediately
|
||||
if self.web_server:
|
||||
self.web_server.notify_new_spot(spot)
|
||||
if self._web_server:
|
||||
self._web_server.notify_new_spot(spot)
|
||||
|
||||
def stop(self):
|
||||
"""Stop any threads and prepare for application shutdown"""
|
||||
|
||||
Reference in New Issue
Block a user