mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-09-20 22:37:44 +00:00
ruff fixes
This commit is contained in:
@@ -84,7 +84,7 @@ def get_activity_ref_info(activity_name, ref_id):
|
|||||||
activity_ref.latitude = ll[0]
|
activity_ref.latitude = ll[0]
|
||||||
activity_ref.longitude = ll[1]
|
activity_ref.longitude = ll[1]
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.warning("Invalid lat/lon received for WAB/WAI reference")
|
logger.warning("Invalid lat/lon received for WAB/WAI reference", exc_info=True)
|
||||||
return activity_ref
|
return activity_ref
|
||||||
|
|
||||||
elif activity_name.upper() == ActivityName.BOTA:
|
elif activity_name.upper() == ActivityName.BOTA:
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
from math import floor
|
from math import floor, isnan
|
||||||
|
|
||||||
from pyproj import Transformer
|
from pyproj import Transformer
|
||||||
from shapely.geometry import Point, Polygon
|
from shapely.geometry import Point, Polygon
|
||||||
@@ -156,7 +156,7 @@ def lat_lon_for_grid_sw_corner_plus_size(grid):
|
|||||||
lat -= 90.0
|
lat -= 90.0
|
||||||
|
|
||||||
# Return None values on maths errors
|
# Return None values on maths errors
|
||||||
if any(x != x for x in [lat, lon, lat_cell_size, lon_cell_size]):
|
if any(isnan(x) for x in [lat, lon, lat_cell_size, lon_cell_size]):
|
||||||
return None, None, None, None
|
return None, None, None, None
|
||||||
|
|
||||||
return lat, lon, lat_cell_size, lon_cell_size
|
return lat, lon, lat_cell_size, lon_cell_size
|
||||||
|
|||||||
+2
-2
@@ -414,12 +414,12 @@ class Spot:
|
|||||||
self.dx_latitude = ll[0]
|
self.dx_latitude = ll[0]
|
||||||
self.dx_longitude = ll[1]
|
self.dx_longitude = ll[1]
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.debug("Invalid grid received for spot")
|
logger.debug("Invalid grid received for spot", exc_info=True)
|
||||||
if self.dx_latitude and self.dx_longitude and not self.dx_grid:
|
if self.dx_latitude and self.dx_longitude and not self.dx_grid:
|
||||||
try:
|
try:
|
||||||
self.dx_grid = latlong_to_locator(self.dx_latitude, self.dx_longitude, 8)
|
self.dx_grid = latlong_to_locator(self.dx_latitude, self.dx_longitude, 8)
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.debug("Invalid lat/lon received for spot")
|
logger.debug("Invalid lat/lon received for spot", exc_info=True)
|
||||||
|
|
||||||
# QRT comment detection
|
# QRT comment detection
|
||||||
if self.comment and not self.qrt:
|
if self.comment and not self.qrt:
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ class WOTA(HTTPAlertProvider):
|
|||||||
if len(ref_split) > 1:
|
if len(ref_split) > 1:
|
||||||
ref_name = str(ref_split[1])
|
ref_name = str(ref_split[1])
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.warning(f"Could not parse WOTA alert title: {source_alert.description}")
|
logger.warning(f"Could not parse WOTA alert title: {source_alert.description}", exc_info=True)
|
||||||
|
|
||||||
# Pick apart the description
|
# Pick apart the description
|
||||||
comment = None
|
comment = None
|
||||||
@@ -64,7 +64,7 @@ class WOTA(HTTPAlertProvider):
|
|||||||
if len(desc_split) > 1:
|
if len(desc_split) > 1:
|
||||||
comment = desc_split[1].strip()
|
comment = desc_split[1].strip()
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.warning(f"Could not parse WOTA alert description: {source_alert.description}")
|
logger.warning(f"Could not parse WOTA alert description: {source_alert.description}", exc_info=True)
|
||||||
|
|
||||||
time = datetime.strptime(source_alert.pub_date.content, self.RSS_DATE_TIME_FORMAT).astimezone(pytz.UTC)
|
time = datetime.strptime(source_alert.pub_date.content, self.RSS_DATE_TIME_FORMAT).astimezone(pytz.UTC)
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ class HamQTH(APIQueryCallsignDataProvider):
|
|||||||
logger.debug("HamQTH login details incorrect, failed to look up with HamQTH.")
|
logger.debug("HamQTH login details incorrect, failed to look up with HamQTH.")
|
||||||
return None
|
return None
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.error("Exception when getting HamQTH session key")
|
logger.exception("Exception when getting HamQTH session key")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if not session_id:
|
if not session_id:
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ class QRZ(APIQueryCallsignDataProvider):
|
|||||||
logger.debug("QRZ.com login details incorrect, failed to look up with QRZ.")
|
logger.debug("QRZ.com login details incorrect, failed to look up with QRZ.")
|
||||||
return None
|
return None
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.error("Exception when getting QRZ.com session key")
|
logger.exception("Exception when getting QRZ.com session key")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if not session_key:
|
if not session_key:
|
||||||
|
|||||||
@@ -118,7 +118,9 @@ class NOAA3dayForecast(HTTPSolarConditionsProvider):
|
|||||||
column_dates = []
|
column_dates = []
|
||||||
for month_str, day_str in date_matches:
|
for month_str, day_str in date_matches:
|
||||||
try:
|
try:
|
||||||
column_dates.append(datetime.strptime(f"{day_str} {month_str} {year}", "%d %b %Y").date())
|
column_dates.append(
|
||||||
|
datetime.strptime(f"{day_str} {month_str} {year}", "%d %b %Y").replace(tzinfo=timezone.utc).date()
|
||||||
|
)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
logger.warning(f"NOAA K-index forecast: could not parse date: {month_str} {day_str} {year}")
|
logger.warning(f"NOAA K-index forecast: could not parse date: {month_str} {day_str} {year}")
|
||||||
return None
|
return None
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ class DXCluster(SpotProvider):
|
|||||||
telnet_output = self._telnet.read_until("\n".encode("latin-1"))
|
telnet_output = self._telnet.read_until("\n".encode("latin-1"))
|
||||||
match = self._spot_line_pattern.match(telnet_output.decode("latin-1"))
|
match = self._spot_line_pattern.match(telnet_output.decode("latin-1"))
|
||||||
if match:
|
if match:
|
||||||
spot_time = datetime.strptime(match.group(5), "%H%MZ")
|
spot_time = datetime.strptime(match.group(5), "%H%MZ").replace(tzinfo=pytz.UTC)
|
||||||
spot_datetime = datetime.combine(
|
spot_datetime = datetime.combine(
|
||||||
datetime.now(pytz.UTC).date(),
|
datetime.now(pytz.UTC).date(),
|
||||||
spot_time.time(),
|
spot_time.time(),
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from typing import ClassVar
|
||||||
|
|
||||||
import pytz
|
import pytz
|
||||||
import requests
|
import requests
|
||||||
@@ -20,7 +21,7 @@ class ParksNPeaks(HTTPSpotProvider):
|
|||||||
POLL_INTERVAL_SEC = 120
|
POLL_INTERVAL_SEC = 120
|
||||||
SPOTS_URL = "https://www.parksnpeaks.org/api/ALL"
|
SPOTS_URL = "https://www.parksnpeaks.org/api/ALL"
|
||||||
SUBMIT_URL = "https://www.parksnpeaks.org/api/SPOT/"
|
SUBMIT_URL = "https://www.parksnpeaks.org/api/SPOT/"
|
||||||
SUBMITTABLE_ACTIVITIES = [
|
SUBMITTABLE_ACTIVITIES: ClassVar[list[ActivityName]] = [
|
||||||
ActivityName.POTA,
|
ActivityName.POTA,
|
||||||
ActivityName.SOTA,
|
ActivityName.SOTA,
|
||||||
ActivityName.WWFF,
|
ActivityName.WWFF,
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ class RBN(SpotProvider):
|
|||||||
telnet_output = self._telnet.read_until("\n".encode("latin-1"))
|
telnet_output = self._telnet.read_until("\n".encode("latin-1"))
|
||||||
match = self._LINE_PATTERN.match(telnet_output.decode("latin-1"))
|
match = self._LINE_PATTERN.match(telnet_output.decode("latin-1"))
|
||||||
if match:
|
if match:
|
||||||
spot_time = datetime.strptime(match.group(5), "%H%MZ")
|
spot_time = datetime.strptime(match.group(5), "%H%MZ").replace(tzinfo=pytz.UTC)
|
||||||
spot_datetime = datetime.combine(
|
spot_datetime = datetime.combine(
|
||||||
datetime.now(pytz.UTC).date(),
|
datetime.now(pytz.UTC).date(),
|
||||||
spot_time.time(),
|
spot_time.time(),
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import logging
|
import logging
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from typing import ClassVar
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from requests.exceptions import ConnectionError, ConnectTimeout, ReadTimeout
|
from requests.exceptions import ConnectionError, ConnectTimeout, ReadTimeout
|
||||||
@@ -24,7 +25,7 @@ class SOTA(HTTPSpotProvider):
|
|||||||
SPOTS_URL = "https://api-db2.sota.org.uk/api/spots/60/all/all"
|
SPOTS_URL = "https://api-db2.sota.org.uk/api/spots/60/all/all"
|
||||||
|
|
||||||
SUBMIT_URL = "https://api-db2.sota.org.uk/api/spots"
|
SUBMIT_URL = "https://api-db2.sota.org.uk/api/spots"
|
||||||
VALID_MODES = ["AM", "CW", "Data", "DV", "FM", "SSB"]
|
VALID_MODES: ClassVar[list[str]] = ["AM", "CW", "Data", "DV", "FM", "SSB"]
|
||||||
|
|
||||||
def __init__(self, provider_config):
|
def __init__(self, provider_config):
|
||||||
super().__init__("SOTA", provider_config, self.EPOCH_URL, self.POLL_INTERVAL_SEC)
|
super().__init__("SOTA", provider_config, self.EPOCH_URL, self.POLL_INTERVAL_SEC)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import logging
|
import logging
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from typing import ClassVar
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
@@ -18,7 +19,7 @@ class Tiles(HTTPSpotProvider):
|
|||||||
POLL_INTERVAL_SEC = 120
|
POLL_INTERVAL_SEC = 120
|
||||||
SPOTS_URL = "https://icneuzxitdqtofutxbla.supabase.co/functions/v1/spots?active_hours=24"
|
SPOTS_URL = "https://icneuzxitdqtofutxbla.supabase.co/functions/v1/spots?active_hours=24"
|
||||||
SUBMIT_URL = "https://icneuzxitdqtofutxbla.supabase.co/functions/v1/self-spot"
|
SUBMIT_URL = "https://icneuzxitdqtofutxbla.supabase.co/functions/v1/self-spot"
|
||||||
VALID_MODES = [
|
VALID_MODES: ClassVar[list[str]] = [
|
||||||
"SSB",
|
"SSB",
|
||||||
"CW",
|
"CW",
|
||||||
"FT8",
|
"FT8",
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ class WebsocketSpotProvider(SpotProvider):
|
|||||||
self._ws.close()
|
self._ws.close()
|
||||||
except Exception:
|
except Exception:
|
||||||
# No problem, we were getting rid of this object anyway.
|
# No problem, we were getting rid of this object anyway.
|
||||||
pass
|
logger.debug(f"Exception while closing socket in {self.name}", exc_info=True)
|
||||||
self._ws = None
|
self._ws = None
|
||||||
if not self._stop_event.is_set():
|
if not self._stop_event.is_set():
|
||||||
self._stop_event.wait(timeout=5) # Wait before trying to reconnect
|
self._stop_event.wait(timeout=5) # Wait before trying to reconnect
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ class WOTA(HTTPSpotProvider):
|
|||||||
if len(ref_split) > 1:
|
if len(ref_split) > 1:
|
||||||
ref_name = str(ref_split[1])
|
ref_name = str(ref_split[1])
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.warning(f"Could not parse WOTA spot title: {source_spot.title}")
|
logger.warning(f"Could not parse WOTA spot title: {source_spot.title}", exc_info=True)
|
||||||
|
|
||||||
# Pick apart the description
|
# Pick apart the description
|
||||||
freq_hz = None
|
freq_hz = None
|
||||||
@@ -75,7 +75,9 @@ class WOTA(HTTPSpotProvider):
|
|||||||
if len(desc_split) > 2:
|
if len(desc_split) > 2:
|
||||||
spotter = desc_split[2].replace("Spotted by ", "").replace(".", "").upper().strip()
|
spotter = desc_split[2].replace("Spotted by ", "").replace(".", "").upper().strip()
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.warning(f"Could not parse WOTA spot description: {source_spot.description}")
|
logger.warning(
|
||||||
|
f"Could not parse WOTA spot description: {source_spot.description}", exc_info=True
|
||||||
|
)
|
||||||
|
|
||||||
time = datetime.strptime(source_spot.pub_date.content, self.RSS_DATE_TIME_FORMAT).astimezone(
|
time = datetime.strptime(source_spot.pub_date.content, self.RSS_DATE_TIME_FORMAT).astimezone(
|
||||||
pytz.UTC
|
pytz.UTC
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ class XOTA(WebsocketSpotProvider):
|
|||||||
is why we also provide a sig_ref_prefix in our config. This is applied to the reference ID, so e.g. "T-01" at C3
|
is why we also provide a sig_ref_prefix in our config. This is applied to the reference ID, so e.g. "T-01" at C3
|
||||||
might become "C3 T-01". This allows us to provide location lookups for TOTA at several conferences."""
|
might become "C3 T-01". This allows us to provide location lookups for TOTA at several conferences."""
|
||||||
|
|
||||||
LOCATION_DATA = {}
|
|
||||||
ACTIVITY = None
|
ACTIVITY = None
|
||||||
|
|
||||||
def __init__(self, provider_config):
|
def __init__(self, provider_config):
|
||||||
|
|||||||
@@ -155,7 +155,8 @@ class TelnetServer:
|
|||||||
writer.close()
|
writer.close()
|
||||||
await writer.wait_closed()
|
await writer.wait_closed()
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
# No problem, we were disconnecting this client anyway.
|
||||||
|
logger.debug("Exception while closing telnet client connection", exc_info=True)
|
||||||
self._clients.clear()
|
self._clients.clear()
|
||||||
|
|
||||||
def publish(self, spot: Spot):
|
def publish(self, spot: Spot):
|
||||||
@@ -178,6 +179,7 @@ class TelnetServer:
|
|||||||
writer.write(encoded_line)
|
writer.write(encoded_line)
|
||||||
await writer.drain()
|
await writer.drain()
|
||||||
except Exception:
|
except Exception:
|
||||||
|
logger.debug("Exception while writing to telnet client, assuming it disconnected", exc_info=True)
|
||||||
disconnected_clients.add(writer)
|
disconnected_clients.add(writer)
|
||||||
|
|
||||||
# Clean up any disconnected connections caught during writing
|
# Clean up any disconnected connections caught during writing
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
|
import logging
|
||||||
|
|
||||||
import tornado
|
import tornado
|
||||||
from tornado.httpclient import AsyncHTTPClient
|
from tornado.httpclient import AsyncHTTPClient
|
||||||
from tornado.httputil import HTTPHeaders
|
from tornado.httputil import HTTPHeaders
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
_LEGACY_PARAM_TO_HEADER_MAP = {
|
_LEGACY_PARAM_TO_HEADER_MAP = {
|
||||||
"qrz_username": "X-QRZ-Username",
|
"qrz_username": "X-QRZ-Username",
|
||||||
"qrz_password": "X-QRZ-Password",
|
"qrz_password": "X-QRZ-Password",
|
||||||
@@ -41,6 +45,7 @@ class V1RedirectHandler(tornado.web.RequestHandler):
|
|||||||
request_timeout=10.0,
|
request_timeout=10.0,
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
logger.exception("Exception when proxying legacy v1 API request")
|
||||||
raise tornado.web.HTTPError(502, reason=str(e))
|
raise tornado.web.HTTPError(502, reason=str(e))
|
||||||
|
|
||||||
self.set_status(response.code, response.reason)
|
self.set_status(response.code, response.reason)
|
||||||
|
|||||||
@@ -42,5 +42,5 @@ class SSEBroadcaster:
|
|||||||
handler.callback(value)
|
handler.callback(value)
|
||||||
except Exception:
|
except Exception:
|
||||||
# Connection probably dropped, ignore and de-register the handler to stop getting future items.
|
# Connection probably dropped, ignore and de-register the handler to stop getting future items.
|
||||||
logger.debug("Failed to push to an SSE client; dropping it")
|
logger.debug("Failed to push to an SSE client; dropping it", exc_info=True)
|
||||||
self.unregister(handler)
|
self.unregister(handler)
|
||||||
|
|||||||
Reference in New Issue
Block a user