Use ruff linter to fix issues and provide consistent formatting

This commit is contained in:
Ian Renton
2026-08-15 08:25:54 +01:00
parent 7391c28cd0
commit af3f82c14d
121 changed files with 1989 additions and 996 deletions
+47 -25
View File
@@ -1,5 +1,4 @@
import hashlib
import hashlib
import json
import logging
import re
@@ -7,16 +6,25 @@ from dataclasses import dataclass
from datetime import datetime, timedelta
import pytz
from pyhamtools.locator import locator_to_latlong, latlong_to_locator
from pyhamtools.locator import latlong_to_locator, locator_to_latlong
from core.call_lookup_helper import get_call_info
from core.config import MAX_SPOT_AGE
from core.constants import MODE_ALIASES, PROPAGATION_MODES
from core.geo_utils import lat_lon_to_cq_zone, lat_lon_to_itu_zone
from core.sig_lookup_helper import populate_missing_sig_ref_info
from core.sig_utils import ANY_SIG_REGEX, get_ref_regex_for_sig, get_sig_name_from_comment_name
from core.utils import infer_band_from_freq, infer_mode_from_comment, \
infer_mode_from_frequency, infer_mode_type_from_mode, get_flag_for_dxcc
from core.sig_utils import (
ANY_SIG_REGEX,
get_ref_regex_for_sig,
get_sig_name_from_comment_name,
)
from core.utils import (
get_flag_for_dxcc,
infer_band_from_freq,
infer_mode_from_comment,
infer_mode_from_frequency,
infer_mode_type_from_mode,
)
from data.sig_ref import SIGRef
@@ -141,10 +149,7 @@ class Spot:
objects such as the sig_refs list.."""
if self.sig_refs:
self.sig_refs = [
sig_ref if isinstance(sig_ref, SIGRef) else SIGRef(**sig_ref)
for sig_ref in self.sig_refs
]
self.sig_refs = [sig_ref if isinstance(sig_ref, SIGRef) else SIGRef(**sig_ref) for sig_ref in self.sig_refs]
def infer_missing(self, credentials=None):
"""Infer missing parameters where possible"""
@@ -207,8 +212,11 @@ class Spot:
# Spotter country, continent, zones etc. from callsign.
# DE call with no digits, or APRS servers starting "T2" are not things we can look up location for
de_call_info = get_call_info(self.de_call, credentials)
if self.de_call and any(char.isdigit() for char in self.de_call) and not (
self.de_call.startswith("T2") and self.source == "APRS-IS"):
if (
self.de_call
and any(char.isdigit() for char in self.de_call)
and not (self.de_call.startswith("T2") and self.source == "APRS-IS")
):
if not self.de_country:
self.de_country = de_call_info.country
if not self.de_continent:
@@ -279,9 +287,11 @@ class Spot:
# If so, add that to the sig_refs list for this spot.
ref_regex = get_ref_regex_for_sig(found_sig)
if ref_regex:
ref_matches = re.finditer(r"(^|\W)" + found_sig + r"([ -])(" + ref_regex + r")($|\W)",
self.comment,
re.IGNORECASE)
ref_matches = re.finditer(
r"(^|\W)" + found_sig + r"([ -])(" + ref_regex + r")($|\W)",
self.comment,
re.IGNORECASE,
)
for ref_match in ref_matches:
self._append_sig_ref_if_missing(SIGRef(id=ref_match.group(3).upper(), sig=found_sig))
@@ -312,8 +322,9 @@ class Spot:
# being the only source we have for propagation mode. Brace for nightmare regex from hell.
if self.comment:
grid_mode_grid_match = re.search(
r'\b([A-Ra-r]{2}\d{2}(?:[A-Xa-x]{2}(?:\d{2})?)?)(?:<([^>]*)>|\(([^)]*)\))([A-Ra-r]{2}\d{2}(?:[A-Xa-x]{2}(?:\d{2})?)?)\b',
self.comment)
r"\b([A-Ra-r]{2}\d{2}(?:[A-Xa-x]{2}(?:\d{2})?)?)(?:<([^>]*)>|\(([^)]*)\))([A-Ra-r]{2}\d{2}(?:[A-Xa-x]{2}(?:\d{2})?)?)\b",
self.comment,
)
if grid_mode_grid_match:
# regex matches, so extract grids:
if not self.de_grid:
@@ -329,13 +340,14 @@ class Spot:
self.propagation_mode = PROPAGATION_MODES[mode_tag]
else:
self.propagation_mode = mode_tag
logging.info("Seen a new propagation mode tag not yet in the system: %s", mode_tag)
logging.info(f"Seen a new propagation mode tag not yet in the system: {mode_tag}")
# Parse "de_grid -> dx_grid" structures from the comment
if self.comment:
grid_mode_grid_match = re.search(
r'\b([A-Ra-r]{2}\d{2}(?:[A-Xa-x]{2}(?:\d{2})?)?)\s*->\s*([A-Ra-r]{2}\d{2}(?:[A-Xa-x]{2}(?:\d{2})?)?)\b',
self.comment)
r"\b([A-Ra-r]{2}\d{2}(?:[A-Xa-x]{2}(?:\d{2})?)?)\s*->\s*([A-Ra-r]{2}\d{2}(?:[A-Xa-x]{2}(?:\d{2})?)?)\b",
self.comment,
)
if grid_mode_grid_match:
# regex matches, so extract grids:
if not self.dx_grid:
@@ -370,7 +382,8 @@ class Spot:
self.id = hashlib.sha256(str({"s": self.source, "sid": self.source_id}).encode("utf-8")).hexdigest()
else:
self.id = hashlib.sha256(
str({"s": self.source, "c": self.dx_call, "t": self.time}).encode("utf-8")).hexdigest()
str({"s": self.source, "c": self.dx_call, "t": self.time}).encode("utf-8")
).hexdigest()
# DX operator details lookup. This should be the last resort compared to taking the data from the actual
# spotting service, e.g. we don't want to accidentally use a user's QRZ.com home lat/lon or DXCC lat/lon
@@ -407,14 +420,23 @@ class Spot:
# DX Location is "good" if it is from a spot, or from QRZ if the callsign doesn't contain a slash, so the operator
# is likely at home.
self.dx_location_good = bool(self.dx_latitude and self.dx_longitude and (
self.dx_location_source == "SPOT" or self.dx_location_source == "SIG REF LOOKUP"
self.dx_location_good = bool(
self.dx_latitude
and self.dx_longitude
and (
self.dx_location_source == "SPOT"
or self.dx_location_source == "SIG REF LOOKUP"
or self.dx_location_source == "GRID"
or (self.dx_location_source == "HOME QTH" and "/" not in (self.dx_call or ""))))
or (self.dx_location_source == "HOME QTH" and "/" not in (self.dx_call or ""))
)
)
# DE with no digits and APRS servers starting "T2" are not things we can look up location for
if self.de_call and any(char.isdigit() for char in str(self.de_call)) and not (
self.de_call.startswith("T2") and self.source == "APRS-IS"):
if (
self.de_call
and any(char.isdigit() for char in str(self.de_call))
and not (self.de_call.startswith("T2") and self.source == "APRS-IS")
):
# DE operator location lookup
if not self.de_latitude:
self.de_latitude = de_call_info.latitude