mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-09-21 14:57:42 +00:00
Partial fix for mypy issues
This commit is contained in:
@@ -128,6 +128,8 @@ class ParksNPeaks(HTTPSpotProvider):
|
||||
raise ValueError(
|
||||
"Parks N Peaks user ID and API key are required. Get yours from your Parks N Peaks account."
|
||||
)
|
||||
if not spot.freq:
|
||||
raise RuntimeError("The Parks N Peaks API requires a frequency to be set.")
|
||||
ref_id = spot.sig_refs[0].id if spot.sig_refs else ""
|
||||
body = {
|
||||
"actClass": spot.sig or "",
|
||||
|
||||
@@ -64,6 +64,8 @@ class POTA(HTTPSpotProvider):
|
||||
def submit_spot(self, spot: Spot, credentials: dict[str, str]) -> None:
|
||||
sig_ref = spot.sig_refs[0].id if spot.sig_refs else None
|
||||
if sig_ref:
|
||||
if not spot.freq:
|
||||
raise RuntimeError("The POTA API requires a frequency to be set.")
|
||||
body = {
|
||||
"activator": spot.dx_call,
|
||||
"spotter": spot.de_call,
|
||||
|
||||
@@ -94,21 +94,24 @@ class SOTA(HTTPSpotProvider):
|
||||
raise ValueError("SOTA API tokens are required. Please log into SOTA in order to spot to it.")
|
||||
sig_ref = spot.sig_refs[0].id if spot.sig_refs else ""
|
||||
if sig_ref:
|
||||
if not spot.freq:
|
||||
raise ValueError("SOTA API requires a frequency to be set.")
|
||||
|
||||
# Split reference into association and summit codes
|
||||
ref_split = sig_ref.split("/")
|
||||
|
||||
# Figure out a valid mode. Borrowed this from PoLo :)
|
||||
# https://github.com/ham2k/app-polo/blob/main/src/extensions/activities/sota/SOTAPostSelfSpot.js
|
||||
mode = spot.mode
|
||||
if mode and mode not in self.VALID_MODES:
|
||||
mode = "Data"
|
||||
mode_str = spot.mode.value if spot.mode else ""
|
||||
if spot.mode and spot.mode not in self.VALID_MODES:
|
||||
mode_str = "Data"
|
||||
|
||||
body = {
|
||||
"activatorCallsign": spot.dx_call,
|
||||
"associationCode": ref_split[0],
|
||||
"summitCode": ref_split[1],
|
||||
"frequency": spot.freq / 1000000.0,
|
||||
"mode": mode or "",
|
||||
"mode": mode_str,
|
||||
"callsign": spot.de_call,
|
||||
"comments": spot.comment or "",
|
||||
"type": "TEST", # todo replatce with NORMAL/QRT once testing complete
|
||||
|
||||
@@ -37,12 +37,12 @@ class SpotProvider:
|
||||
# off to SSE listeners.
|
||||
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:
|
||||
if datetime.fromtimestamp(spot.time or 0, pytz.UTC) > self.last_spot_time:
|
||||
# Fill in any blanks and add to the list
|
||||
spot.infer_missing()
|
||||
self._add_spot(spot)
|
||||
if spots:
|
||||
self.last_spot_time = datetime.fromtimestamp(max(s.time for s in spots), pytz.UTC)
|
||||
self.last_spot_time = datetime.fromtimestamp(max(s.time or 0 for s in spots), pytz.UTC)
|
||||
|
||||
def _submit(self, spot: Spot) -> None:
|
||||
"""Submit a single spot retrieved from the provider. This will be added to the list regardless of its age. Spots
|
||||
@@ -52,9 +52,10 @@ class SpotProvider:
|
||||
# Fill in any blanks and add to the list
|
||||
spot.infer_missing()
|
||||
self._add_spot(spot)
|
||||
self.last_spot_time = datetime.fromtimestamp(spot.time, pytz.UTC)
|
||||
self.last_spot_time = datetime.fromtimestamp(spot.time or 0, pytz.UTC)
|
||||
|
||||
def _add_spot(self, spot: Spot) -> None:
|
||||
assert spot.id is not None, "infer_missing() always assigns an id"
|
||||
if not spot.expired():
|
||||
self._spots.set(spot.id, spot)
|
||||
|
||||
|
||||
+11
-8
@@ -90,22 +90,25 @@ class Tiles(HTTPSpotProvider):
|
||||
def submit_spot(self, spot: Spot, credentials: dict[str, str]) -> None:
|
||||
# Tiles on the air currently only supports *self* spots
|
||||
if spot.dx_call == spot.de_call:
|
||||
if not spot.freq:
|
||||
raise RuntimeError("The Tiles on the Air API requires a frequency to be set.")
|
||||
|
||||
# Figure out a valid mode. Borrowed this from PoLo :)
|
||||
# https://github.com/ham2k/app-polo/blob/main/src/extensions/activities/sota/SOTAPostSelfSpot.js
|
||||
if spot.mode:
|
||||
mode = spot.mode
|
||||
if mode not in self.VALID_MODES:
|
||||
if mode == "OLIVIA":
|
||||
mode = "Olivia"
|
||||
elif mode == "JS8":
|
||||
mode = "JS8Call"
|
||||
mode_str: str = spot.mode.value
|
||||
if spot.mode not in self.VALID_MODES:
|
||||
if spot.mode == "OLIVIA":
|
||||
mode_str = "Olivia"
|
||||
elif spot.mode == "JS8":
|
||||
mode_str = "JS8Call"
|
||||
else:
|
||||
mode = "Other"
|
||||
mode_str = "Other"
|
||||
|
||||
body = {
|
||||
"call_sign": spot.dx_call,
|
||||
"frequency": str(spot.freq / 1000000.0),
|
||||
"mode": mode or "",
|
||||
"mode": mode_str or "",
|
||||
"grid": spot.dx_grid or "",
|
||||
"comment": spot.comment or "",
|
||||
"lat": spot.dx_latitude or None,
|
||||
|
||||
Reference in New Issue
Block a user