flynt pass to provide consistency to string formatters and concatenation

This commit is contained in:
Ian Renton
2026-08-15 07:55:32 +01:00
parent bff5b79f8f
commit 7391c28cd0
72 changed files with 184 additions and 193 deletions
+10 -10
View File
@@ -54,19 +54,19 @@ class DXCluster(SpotProvider):
while not connected and self._running:
try:
self.status = "Connecting"
logging.info("DX Cluster " + self._hostname + " connecting...")
logging.info(f"DX Cluster {self._hostname} connecting...")
self._telnet = telnetlib3.Telnet(self._hostname, self._port)
self._telnet.read_until(self._login_prompt.encode("latin-1"))
self._telnet.write((self._login_callsign + "\n").encode("latin-1"))
self._telnet.write(f"{self._login_callsign}\n".encode("latin-1"))
connected = True
logging.info("DX Cluster " + self._hostname + " connected.")
logging.info(f"DX Cluster {self._hostname} connected.")
except ConnectionRefusedError:
self.status = "Error"
logging.warning("Connection refused to DX cluster " + self._hostname)
logging.warning(f"Connection refused to DX cluster {self._hostname}")
sleep(300)
except Exception:
self.status = "Error"
logging.exception("Exception while connecting to DX Cluster Provider (" + self._hostname + ").")
logging.exception(f"Exception while connecting to DX Cluster Provider ({self._hostname}).")
sleep(5)
self.status = "Waiting for Data"
@@ -91,25 +91,25 @@ class DXCluster(SpotProvider):
self.status = "OK"
self.last_update_time = datetime.now(pytz.UTC)
logging.debug("Data received from DX Cluster " + self._hostname + ".")
logging.debug(f"Data received from DX Cluster {self._hostname}.")
except EOFError:
connected = False
if self._running:
self.status = "Restarting"
logging.warning("Disconnected from DX Cluster " + self._hostname + ". Reconnecting...")
logging.warning(f"Disconnected from DX Cluster {self._hostname}. Reconnecting...")
sleep(5)
else:
logging.info("DX Cluster " + self._hostname + " shutting down...")
logging.info(f"DX Cluster {self._hostname} shutting down...")
self.status = "Shutting down"
except Exception:
connected = False
if self._running:
self.status = "Error"
logging.exception("Exception in DX Cluster Provider (" + self._hostname + ")")
logging.exception(f"Exception in DX Cluster Provider ({self._hostname})")
sleep(5)
else:
logging.info("DX Cluster " + self._hostname + " shutting down...")
logging.info(f"DX Cluster {self._hostname} shutting down...")
self.status = "Shutting down"
self.status = "Disconnected"
+3 -5
View File
@@ -27,7 +27,7 @@ class GMA(HTTPSpotProvider):
logging.warning("GMA spot provider configured but no api key was provided, this API will not be queried.")
self._url_data_cache = URLDataCache("GMA")
super().__init__("GMA", provider_config, self.SPOTS_URL + "?key=" + self._api_key, self.POLL_INTERVAL_SEC)
super().__init__("GMA", provider_config, f"{self.SPOTS_URL}?key={self._api_key}", self.POLL_INTERVAL_SEC)
def _http_response_to_spots(self, http_response):
new_spots = []
@@ -98,8 +98,7 @@ class GMA(HTTPSpotProvider):
spot.sig_refs[0].sig = "MOTA"
spot.sig = "MOTA"
case _:
logging.warning("GMA spot found with ref type " + ref_info[
"reftype"] + ", developer needs to add support for this!")
logging.warning(f"GMA spot found with ref type {ref_info['reftype']}, developer needs to add support for this!")
spot.sig_refs[0].sig = ref_info["reftype"]
spot.sig = ref_info["reftype"]
@@ -115,8 +114,7 @@ class GMA(HTTPSpotProvider):
logging.warning(
f"GMA API returned a malformed response when looking up ref {source_spot['REF']}")
except:
logging.exception("Exception when looking up " + self.REF_INFO_URL_ROOT + source_spot[
"REF"] + ", ignoring this spot for now")
logging.exception(f"Exception when looking up {self.REF_INFO_URL_ROOT}{source_spot['REF']}, ignoring this spot for now")
else:
logging.warning(f"The GMA API returned an unexpected response (HTTP {http_response.status_code}).")
+4 -4
View File
@@ -26,7 +26,7 @@ class HTTPSpotProvider(SpotProvider):
def start(self):
# Fire off the polling thread. It will poll immediately on startup, then sleep for poll_interval between
# subsequent polls, so start() returns immediately and the application can continue starting.
logging.info("Set up query of " + self.name + " spot API every " + str(self._poll_interval) + " seconds.")
logging.info(f"Set up query of {self.name} spot API every {self._poll_interval!s} seconds.")
self._thread = Thread(target=self._run, name=f"HTTPSpotProvider-{self.name}")
self._thread.start()
@@ -50,7 +50,7 @@ class HTTPSpotProvider(SpotProvider):
def _poll(self):
try:
# Request data from API
logging.debug("Polling " + self.name + " spot API...")
logging.debug(f"Polling {self.name} spot API...")
http_response = requests.get(self._url, headers=HTTP_HEADERS, timeout=(5, 30))
# Check response code was good
if http_response.ok:
@@ -62,7 +62,7 @@ class HTTPSpotProvider(SpotProvider):
self.status = "OK"
self.last_update_time = datetime.now(pytz.UTC)
logging.debug("Received data from " + self.name + " spot API.")
logging.debug(f"Received data from {self.name} spot API.")
else:
self.status = "Error"
logging.warning(f"HTTP {http_response.status_code} when calling {self.name} spot API.")
@@ -73,7 +73,7 @@ class HTTPSpotProvider(SpotProvider):
logging.warning(f"Timeout when accessing {self.name} spots API.")
except Exception:
self.status = "Error"
logging.exception("Exception in HTTP Spot Provider (" + self.name + ")")
logging.exception(f"Exception in HTTP Spot Provider ({self.name})")
self._stop_event.wait(timeout=1)
def _http_response_to_spots(self, http_response):
+2 -2
View File
@@ -62,7 +62,7 @@ class ParksNPeaks(HTTPSpotProvider):
# Log a warning for the developer if PnP gives us an unknown programme we've never seen before
if sig not in ["POTA", "SOTA", "WWFF", "SIOTA", "ZLOTA", "KRMNPA", "SANPCPA", "LLOTA"]:
logging.warning("PNP spot found with sig " + sig + ", developer needs to add support for this!")
logging.warning(f"PNP spot found with sig {sig}, developer needs to add support for this!")
# Add new spot to the list
new_spots.append(spot)
@@ -91,4 +91,4 @@ class ParksNPeaks(HTTPSpotProvider):
}
response = requests.post(self.SUBMIT_URL, json=body, headers=HTTP_HEADERS, timeout=(5, 30))
if not response.ok:
raise RuntimeError("Parks N Peaks API returned " + str(response.status_code) + ": " + response.text)
raise RuntimeError(f"Parks N Peaks API returned {response.status_code!s}: {response.text}")
+1 -1
View File
@@ -63,6 +63,6 @@ class POTA(HTTPSpotProvider):
headers = {**HTTP_HEADERS, "Content-Type": "application/json"}
response = requests.post(self.SUBMIT_URL, json=body, headers=headers, timeout=(5, 30))
if not response.ok:
raise RuntimeError("POTA API returned " + str(response.status_code) + ": " + response.text)
raise RuntimeError(f"POTA API returned {response.status_code!s}: {response.text}")
else:
raise RuntimeError("Park reference is required for submitting POTA spots.")
+9 -9
View File
@@ -45,15 +45,15 @@ class RBN(SpotProvider):
while not connected and self._running:
try:
self.status = "Connecting"
logging.info("RBN port " + str(self._port) + " connecting...")
logging.info(f"RBN port {self._port!s} connecting...")
self._telnet = telnetlib3.Telnet("telnet.reversebeacon.net", self._port)
self._telnet.read_until("Please enter your call: ".encode("latin-1"))
self._telnet.write((SERVER_OWNER_CALLSIGN + "\n").encode("latin-1"))
self._telnet.write(f"{SERVER_OWNER_CALLSIGN}\n".encode("latin-1"))
connected = True
logging.info("RBN port " + str(self._port) + " connected.")
logging.info(f"RBN port {self._port!s} connected.")
except Exception:
self.status = "Error"
logging.exception("Exception while connecting to RBN (port " + str(self._port) + ").")
logging.exception(f"Exception while connecting to RBN (port {self._port!s}).")
sleep(5)
self.status = "Waiting for Data"
@@ -78,25 +78,25 @@ class RBN(SpotProvider):
self.status = "OK"
self.last_update_time = datetime.now(pytz.UTC)
logging.debug("Data received from RBN on port " + str(self._port) + ".")
logging.debug(f"Data received from RBN on port {self._port!s}.")
except EOFError:
connected = False
if self._running:
self.status = "Restarting"
logging.warning("Disconnected from RBN provider (port " + str(self._port) + "). Reconnecting...")
logging.warning(f"Disconnected from RBN provider (port {self._port!s}). Reconnecting...")
sleep(5)
else:
logging.info("RBN provider (port " + str(self._port) + ") shutting down...")
logging.info(f"RBN provider (port {self._port!s}) shutting down...")
self.status = "Shutting down"
except Exception:
connected = False
if self._running:
self.status = "Error"
logging.exception("Exception in RBN provider (port " + str(self._port) + ")")
logging.exception(f"Exception in RBN provider (port {self._port!s})")
sleep(5)
else:
logging.info("RBN provider (port " + str(self._port) + ") shutting down...")
logging.info(f"RBN provider (port {self._port!s}) shutting down...")
self.status = "Shutting down"
self.status = "Disconnected"
+2 -2
View File
@@ -104,10 +104,10 @@ class SOTA(HTTPSpotProvider):
"comments": spot.comment or "",
"type": "TEST" # todo replatce with NORMAL/QRT once testing complete
}
headers = {**HTTP_HEADERS, "Authorization": "bearer " + access_token, "id_token": id_token,
headers = {**HTTP_HEADERS, "Authorization": f"bearer {access_token}", "id_token": id_token,
"Content-Type": "application/json"}
response = requests.post(self.SUBMIT_URL, json=body, headers=headers, timeout=(5, 30))
if not response.ok:
raise RuntimeError("SOTA API returned " + str(response.status_code) + ": " + response.text)
raise RuntimeError(f"SOTA API returned {response.status_code!s}: {response.text}")
else:
raise RuntimeError("Summit reference is required for submitting SOTA spots.")
+7 -7
View File
@@ -22,7 +22,7 @@ class SSESpotProvider(SpotProvider):
self._event_source = None
def start(self):
logging.info("Set up SSE connection to " + self.name + " spot API.")
logging.info(f"Set up SSE connection to {self.name} spot API.")
self._stop_event.clear()
self._thread = Thread(target=self._run, name=f"SSESpotProvider-{self.name}")
self._thread.daemon = True
@@ -38,12 +38,12 @@ class SSESpotProvider(SpotProvider):
event_source.close()
except Exception:
logging.exception(
"Exception closing SSE connection for " + self.name + " during stop()")
f"Exception closing SSE connection for {self.name} during stop()")
if self._thread:
self._thread.join(timeout=15)
if self._thread.is_alive():
logging.warning(self.name + " SSE worker thread did not exit on time and will be killed.")
logging.warning(f"{self.name} SSE worker thread did not exit on time and will be killed.")
def _on_open(self):
self.status = "Waiting for Data"
@@ -58,7 +58,7 @@ class SSESpotProvider(SpotProvider):
def _run(self):
while not self._stop_event.is_set():
try:
logging.debug("Connecting to " + self.name + " spot API...")
logging.debug(f"Connecting to {self.name} spot API...")
self.status = "Connecting"
with EventSource(self._url, headers=HTTP_HEADERS, latest_event_id=self._last_event_id, timeout=10,
on_open=self._on_open, on_error=self._on_error) as event_source:
@@ -76,17 +76,17 @@ class SSESpotProvider(SpotProvider):
self.status = "OK"
self.last_update_time = datetime.now(pytz.UTC)
logging.debug("Received data from " + self.name + " spot API.")
logging.debug(f"Received data from {self.name} spot API.")
except Exception:
logging.exception(
"Exception processing message from SSE Spot Provider (" + self.name + ")")
f"Exception processing message from SSE Spot Provider ({self.name})")
finally:
self._set_event_source(None)
except Exception:
self.status = "Error"
logging.exception("Exception in SSE Spot Provider (" + self.name + ")")
logging.exception(f"Exception in SSE Spot Provider ({self.name})")
else:
self.status = "Disconnected"
self._stop_event.wait(timeout=5) # Wait before trying to reconnect
+2 -2
View File
@@ -86,7 +86,7 @@ class Tiles(HTTPSpotProvider):
response = requests.post(self.SUBMIT_URL, json=body, headers=headers, timeout=(5, 30))
if not response.ok:
raise RuntimeError(
"Tiles on the Air API returned " + str(response.status_code) + ": " + response.text)
f"Tiles on the Air API returned {response.status_code!s}: {response.text}")
else:
raise RuntimeError("The Tiles on the Air API requires a mode to be set.")
else:
@@ -100,4 +100,4 @@ def strip_extra_decimal_points(s):
parts = s.split('.', 1)
if len(parts) == 1:
return s
return parts[0] + '.' + parts[1].replace('.', '')
return f"{parts[0]}.{parts[1].replace('.', '')}"
+3 -5
View File
@@ -35,11 +35,9 @@ class UKPacketNet(HTTPSpotProvider):
# First build a "full" comment combining some of the extra info
comment = listed_port["comment"] if "comment" in listed_port else ""
comment = (comment + " " + listed_port["mode"]) if "mode" in listed_port else comment
comment = (comment + " " + listed_port[
"modulation"]) if "modulation" in listed_port else comment
comment = (comment + " " + str(
listed_port["baud"]) + " baud") if "baud" in listed_port and listed_port[
comment = f"{comment} {listed_port['mode']}" if "mode" in listed_port else comment
comment = f"{comment} {listed_port['modulation']}" if "modulation" in listed_port else comment
comment = f"{comment} {listed_port['baud']!s} baud" if "baud" in listed_port and listed_port[
"baud"] > 0 else comment
# Get frequency from the comment if it's not set properly in the data structure. This is
+5 -5
View File
@@ -22,7 +22,7 @@ class WebsocketSpotProvider(SpotProvider):
self._last_event_id = None
def start(self):
logging.info("Set up websocket connection to " + self.name + " spot API.")
logging.info(f"Set up websocket connection to {self.name} spot API.")
self._stopped = False
self._thread = Thread(target=self._run, name=f"WebsocketSpotProvider-{self.name}")
self._thread.daemon = True
@@ -44,7 +44,7 @@ class WebsocketSpotProvider(SpotProvider):
def _run(self):
while not self._stopped:
try:
logging.debug("Connecting to " + self.name + " spot API...")
logging.debug(f"Connecting to {self.name} spot API...")
self.status = "Connecting"
self._ws = create_connection(self._url, header=HTTP_HEADERS)
self.status = "Connected"
@@ -57,15 +57,15 @@ class WebsocketSpotProvider(SpotProvider):
self.status = "OK"
self.last_update_time = datetime.now(pytz.UTC)
logging.debug("Received data from " + self.name + " spot API.")
logging.debug(f"Received data from {self.name} spot API.")
except Exception:
logging.exception(
"Exception processing message from Websocket Spot Provider (" + self.name + ")")
f"Exception processing message from Websocket Spot Provider ({self.name})")
except Exception as e:
self.status = "Error"
logging.exception("Exception in Websocket Spot Provider (" + self.name + ")", e)
logging.exception(f"Exception in Websocket Spot Provider ({self.name})", e)
else:
self.status = "Disconnected"
sleep(5) # Wait before trying to reconnect
+1 -1
View File
@@ -28,7 +28,7 @@ class XOTA(WebsocketSpotProvider):
def _ws_message_to_spot(self, b):
string = b.decode("utf-8")
source_spot = json.loads(string)
ref_id = self._sig_ref_prefix + " " + source_spot["reference"]["title"]
ref_id = f"{self._sig_ref_prefix} {source_spot['reference']['title']}"
spot = Spot(source=self.name,
source_id=source_spot["id"],
dx_call=source_spot["stationCallSign"].upper(),