Refactor activity names to use an enum instead of a string to avoid typos #147

This commit is contained in:
Ian Renton
2026-09-18 18:09:41 +01:00
parent ab79e7e01c
commit e5caf7353d
61 changed files with 735 additions and 638 deletions
+18 -17
View File
@@ -4,7 +4,8 @@ from datetime import datetime
import pytz
from core.constants import HTTP_HEADERS
from core.enums import ActivityRefType, Mode
from core.enums import Mode
from core.enums import ActivityName, ActivityRefType
from core.url_data_cache import URLDataCache
from data.activity_ref import ActivityRef
from data.spot import Spot
@@ -106,40 +107,40 @@ class GMA(HTTPSpotProvider):
spot.sig_refs
and ref_info
and "reftype" in ref_info
and ref_info["reftype"] not in ["POTA", "WWFF"]
and ref_info["reftype"] not in [ActivityName.POTA, ActivityName.WWFF]
and (
ref_info["reftype"] != "Summit" or "sota" not in ref_info or ref_info["sota"] == ""
)
):
match ref_info["reftype"]:
case "Summit":
spot.sig_refs[0].sig = "GMA"
spot.sig_refs[0].sig = ActivityName.GMA
spot.sig_refs[0].ref_type = ActivityRefType.SUMMIT
spot.sig = "GMA"
spot.sig = ActivityName.GMA
case "IOTA Island":
spot.sig_refs[0].sig = "IOTA"
spot.sig_refs[0].sig = ActivityName.IOTA
spot.sig_refs[0].ref_type = ActivityRefType.ISLAND
spot.sig = "IOTA"
spot.sig = ActivityName.IOTA
case "GMA Island":
spot.sig_refs[0].sig = "GMA Islands"
spot.sig_refs[0].sig = ActivityName.GMA_ISLANDS
spot.sig_refs[0].ref_type = ActivityRefType.ISLAND
spot.sig = "GMA Islands"
spot.sig = ActivityName.GMA_ISLANDS
case "Lighthouse (ILLW)":
spot.sig_refs[0].sig = "ILLW"
spot.sig_refs[0].sig = ActivityName.ILLW
spot.sig_refs[0].ref_type = ActivityRefType.LIGHTHOUSE
spot.sig = "ILLW"
spot.sig = ActivityName.ILLW
case "Lighthouse (ARLHS)":
spot.sig_refs[0].sig = "ARLHS"
spot.sig_refs[0].sig = ActivityName.ARLHS
spot.sig_refs[0].ref_type = ActivityRefType.LIGHTHOUSE
spot.sig = "ARLHS"
spot.sig = ActivityName.ARLHS
case "Castle":
spot.sig_refs[0].sig = "WCA"
spot.sig_refs[0].sig = ActivityName.WCA
spot.sig_refs[0].ref_type = ActivityRefType.CASTLE
spot.sig = "WCA"
spot.sig = ActivityName.WCA
case "Mill":
spot.sig_refs[0].sig = "MOTA"
spot.sig_refs[0].sig = ActivityName.MOTA
spot.sig_refs[0].ref_type = ActivityRefType.MILL
spot.sig = "MOTA"
spot.sig = ActivityName.MOTA
case _:
logger.warning(
f"GMA spot found with ref type {ref_info['reftype']}, developer needs to add support for this!"
@@ -170,7 +171,7 @@ class GMA(HTTPSpotProvider):
return new_spots
def can_submit_spot(self, activity):
return activity == "GMA"
return activity == ActivityName.GMA
def submit_spot(self, spot, credentials):
# TODO: Implement.
+5 -4
View File
@@ -7,7 +7,8 @@ import requests
from requests.exceptions import ConnectionError, ConnectTimeout, ReadTimeout
from core.constants import HTTP_HEADERS
from core.enums import ActivityRefType, Mode
from core.enums import Mode
from core.enums import ActivityName, ActivityRefType
from data.activity_ref import ActivityRef
from data.spot import Spot
from providers.spot.http_spot_provider import HTTPSpotProvider
@@ -62,11 +63,11 @@ class HEMA(HTTPSpotProvider):
freq=float(freq_mode_match.group(1)) * 1000000,
mode=Mode.from_name(freq_mode_match.group(2).upper()),
comment=spotter_comment_match.group(2),
sig="HEMA",
sig=ActivityName.HEMA,
sig_refs=[
ActivityRef(
id=spot_items[3].upper(),
sig="HEMA",
sig=ActivityName.HEMA,
name=spot_items[4],
latitude=float(spot_items[7]),
longitude=float(spot_items[8]),
@@ -90,7 +91,7 @@ class HEMA(HTTPSpotProvider):
return new_spots
def can_submit_spot(self, activity):
return activity == "HEMA"
return activity == ActivityName.HEMA
def submit_spot(self, spot, credentials):
# TODO: Implement. Currently blocked awaiting their API team to make a change to allow us to spot with a
+4 -3
View File
@@ -1,6 +1,7 @@
from datetime import datetime
from core.enums import ActivityRefType, Mode
from core.enums import Mode
from core.enums import ActivityName, ActivityRefType
from data.activity_ref import ActivityRef
from data.spot import Spot
from providers.spot.http_spot_provider import HTTPSpotProvider
@@ -34,11 +35,11 @@ class LLOTA(HTTPSpotProvider):
freq=float(source_spot["frequency"]) * 1000000,
mode=Mode.from_name(source_spot["mode"].upper()),
comment=comment,
sig="LLOTA",
sig=ActivityName.LLOTA,
sig_refs=[
ActivityRef(
id=source_spot["reference"],
sig="LLOTA",
sig=ActivityName.LLOTA,
name=source_spot["reference_name"],
ref_type=ActivityRefType.LAKE,
)
+20 -19
View File
@@ -7,6 +7,7 @@ import requests
from core.constants import HTTP_HEADERS
from core.enums import Mode
from core.enums import ActivityName
from data.activity_ref import ActivityRef
from data.spot import Spot
from providers.spot.http_spot_provider import HTTPSpotProvider
@@ -21,15 +22,15 @@ class ParksNPeaks(HTTPSpotProvider):
SPOTS_URL = "https://www.parksnpeaks.org/api/ALL"
SUBMIT_URL = "https://www.parksnpeaks.org/api/SPOT/"
SUBMITTABLE_ACTIVITIES = [
"POTA",
"SOTA",
"WWFF",
"HEMA",
"WOTA",
"ZLOTA",
"SIOTA",
"KRMNPA",
"SANPCPA",
ActivityName.POTA,
ActivityName.SOTA,
ActivityName.WWFF,
ActivityName.HEMA,
ActivityName.WOTA,
ActivityName.ZLOTA,
ActivityName.SIOTA,
ActivityName.KRMNPA,
ActivityName.SANPCPA,
]
def __init__(self, provider_config):
@@ -68,7 +69,7 @@ class ParksNPeaks(HTTPSpotProvider):
# programme with a defined set of references
activity = source_spot["actClass"].upper()
ref_id = source_spot["actSiteID"]
if activity and activity != "" and activity != "QRP" and ref_id and ref_id != "":
if activity and activity != "" and activity != ActivityName.QRP and ref_id and ref_id != "":
spot.sig = activity
activity_refs = [
ActivityRef(
@@ -84,15 +85,15 @@ class ParksNPeaks(HTTPSpotProvider):
# Log a warning for the developer if PnP gives us an unknown programme we've never seen before
if activity not in [
"POTA",
"SOTA",
"WWFF",
"HEMA",
"SIOTA",
"ZLOTA",
"KRMNPA",
"SANPCPA",
"LLOTA",
ActivityName.POTA,
ActivityName.SOTA,
ActivityName.WWFF,
ActivityName.HEMA,
ActivityName.SIOTA,
ActivityName.ZLOTA,
ActivityName.KRMNPA,
ActivityName.SANPCPA,
ActivityName.LLOTA,
]:
logger.warning(f"PNP spot found with activity {activity}, developer needs to add support for this!")
+5 -4
View File
@@ -4,7 +4,8 @@ import pytz
import requests
from core.constants import HTTP_HEADERS
from core.enums import ActivityRefType, Mode
from core.enums import Mode
from core.enums import ActivityName, ActivityRefType
from data.activity_ref import ActivityRef
from data.spot import Spot
from providers.spot.http_spot_provider import HTTPSpotProvider
@@ -33,11 +34,11 @@ class POTA(HTTPSpotProvider):
freq=float(source_spot["frequency"]) * 1000 if source_spot["frequency"] != "INVALID" else None,
mode=Mode.from_name(source_spot["mode"].upper()),
comment=source_spot["comments"],
sig="POTA",
sig=ActivityName.POTA,
sig_refs=[
ActivityRef(
id=source_spot["reference"],
sig="POTA",
sig=ActivityName.POTA,
name=source_spot["name"],
latitude=source_spot["latitude"],
longitude=source_spot["longitude"],
@@ -58,7 +59,7 @@ class POTA(HTTPSpotProvider):
return new_spots
def can_submit_spot(self, activity):
return activity == "POTA"
return activity == ActivityName.POTA
def submit_spot(self, spot, credentials):
sig_ref = spot.sig_refs[0].id if spot.sig_refs else None
+5 -4
View File
@@ -5,7 +5,8 @@ import requests
from requests.exceptions import ConnectionError, ConnectTimeout, ReadTimeout
from core.constants import HTTP_HEADERS
from core.enums import ActivityRefType, Mode
from core.enums import Mode
from core.enums import ActivityName, ActivityRefType
from data.activity_ref import ActivityRef
from data.spot import Spot
from providers.spot.http_spot_provider import HTTPSpotProvider
@@ -56,11 +57,11 @@ class SOTA(HTTPSpotProvider):
# Seen SOTA spots with no frequency!
mode=Mode.from_name(source_spot["mode"].upper()),
comment=source_spot["comments"],
sig="SOTA",
sig=ActivityName.SOTA,
sig_refs=[
ActivityRef(
id=source_spot["summitCode"],
sig="SOTA",
sig=ActivityName.SOTA,
name=source_spot["summitName"],
latitude=source_spot["latitude"],
longitude=source_spot["longitude"],
@@ -83,7 +84,7 @@ class SOTA(HTTPSpotProvider):
return new_spots
def can_submit_spot(self, activity):
return activity == "SOTA"
return activity == ActivityName.SOTA
def submit_spot(self, spot, credentials):
# TODO test this method works
+5 -4
View File
@@ -4,7 +4,8 @@ from datetime import datetime
import requests
from core.constants import HTTP_HEADERS
from core.enums import ActivityRefType, LocationSourceForSpot, Mode
from core.enums import LocationSourceForSpot, Mode
from core.enums import ActivityName, ActivityRefType
from data.activity_ref import ActivityRef
from data.spot import Spot
from providers.spot.http_spot_provider import HTTPSpotProvider
@@ -58,13 +59,13 @@ class Tiles(HTTPSpotProvider):
freq=freq,
mode=Mode.from_name(source_spot["mode"].upper()),
comment=source_spot["notes"],
sig="Tiles",
sig=ActivityName.TILES,
# Tiles spots can include POTA & SOTA references, but ignore those on the basis that we will get them separately from the POTA/SOTA providers anyway.
# Just take the grid reference itself as the single Tiles activity reference.
sig_refs=[
ActivityRef(
id=source_spot["maidenhead_grid"],
sig="Tiles",
sig=ActivityName.TILES,
name=source_spot["maidenhead_grid"],
latitude=source_spot["latitude"],
longitude=source_spot["longitude"],
@@ -84,7 +85,7 @@ class Tiles(HTTPSpotProvider):
return new_spots
def can_submit_spot(self, activity):
return activity == "Tiles"
return activity == ActivityName.TILES
def submit_spot(self, spot, credentials):
# Tiles on the air currently only supports *self* spots
+3 -3
View File
@@ -3,7 +3,7 @@ from datetime import datetime
import pytz
from core.enums import ActivityRefType
from core.enums import ActivityName, ActivityRefType
from data.activity_ref import ActivityRef
from data.spot import Spot
from providers.spot.http_spot_provider import HTTPSpotProvider
@@ -34,8 +34,8 @@ class Towers(HTTPSpotProvider):
dx_call=source_spot["call"].upper(),
freq=likely_freq,
comment=source_spot["comment"],
sig="Towers",
sig_refs=[ActivityRef(id=source_spot["ref"], sig="Towers", ref_type=ActivityRefType.TOWER)],
sig=ActivityName.TOWERS,
sig_refs=[ActivityRef(id=source_spot["ref"], sig=ActivityName.TOWERS, ref_type=ActivityRefType.TOWER)],
time=datetime.strptime(response_json["updated"][:10] + source_spot["time"], "%Y-%m-%d%H:%M")
.replace(tzinfo=pytz.utc)
.timestamp(),
+9 -4
View File
@@ -8,7 +8,8 @@ import pytz
from rss_parser import Parser
from rss_parser.models.rss import RSS
from core.enums import ActivityRefType, Mode
from core.enums import Mode
from core.enums import ActivityName, ActivityRefType
from data.activity_ref import ActivityRef
from data.spot import Spot
from providers.spot.http_spot_provider import HTTPSpotProvider
@@ -90,8 +91,12 @@ class WOTA(HTTPSpotProvider):
freq=freq_hz,
mode=Mode.from_name(mode),
comment=comment,
sig="WOTA",
sig_refs=[ActivityRef(id=ref, sig="WOTA", name=ref_name, ref_type=ActivityRefType.SUMMIT)] if ref else [],
sig=ActivityName.WOTA,
sig_refs=(
[ActivityRef(id=ref, sig=ActivityName.WOTA, name=ref_name, ref_type=ActivityRefType.SUMMIT)]
if ref
else []
),
time=time.timestamp(),
)
@@ -105,7 +110,7 @@ class WOTA(HTTPSpotProvider):
return new_spots
def can_submit_spot(self, activity):
return activity == "WOTA"
return activity == ActivityName.WOTA
def submit_spot(self, spot, credentials):
# TODO Ask M5TEA if he's happy to share how this is done from his app
+5 -4
View File
@@ -1,7 +1,8 @@
import json
from datetime import datetime
from core.enums import ActivityRefType, Mode
from core.enums import Mode
from core.enums import ActivityName, ActivityRefType
from data.activity_ref import ActivityRef
from data.spot import Spot
from providers.spot.sse_spot_provider import SSESpotProvider
@@ -23,7 +24,7 @@ class WWBOTA(SSESpotProvider):
for ref in source_spot["references"]:
activity_ref = ActivityRef(
id=ref["reference"],
sig="WWBOTA",
sig=ActivityName.WWBOTA,
name=ref["name"],
latitude=ref["lat"],
longitude=ref["long"],
@@ -38,7 +39,7 @@ class WWBOTA(SSESpotProvider):
freq=float(source_spot["freq"]) * 1000000,
mode=Mode.from_name(source_spot["mode"].upper()) if "mode" in source_spot else None,
comment=source_spot["comment"],
sig="WWBOTA",
sig=ActivityName.WWBOTA,
sig_refs=refs,
time=datetime.fromisoformat(source_spot["time"].replace("Z", "+00:00")).timestamp(),
# WWBOTA spots can contain multiple references for bunkers being activated simultaneously. For
@@ -53,7 +54,7 @@ class WWBOTA(SSESpotProvider):
return spot if source_spot["type"] != "Test" else None
def can_submit_spot(self, activity):
return activity == "WWBOTA"
return activity == ActivityName.WWBOTA
def submit_spot(self, spot, credentials):
# TODO: Implement. WWBOTA API docs cover this: https://api.wwbota.org/#tag/Spots/operation/create_spot_spots__post
+5 -4
View File
@@ -2,7 +2,8 @@ from datetime import datetime
import pytz
from core.enums import ActivityRefType, Mode
from core.enums import Mode
from core.enums import ActivityName, ActivityRefType
from data.activity_ref import ActivityRef
from data.spot import Spot
from providers.spot.http_spot_provider import HTTPSpotProvider
@@ -30,11 +31,11 @@ class WWFF(HTTPSpotProvider):
freq=float(source_spot["frequency_khz"]) * 1000,
mode=Mode.from_name(source_spot["mode"].upper()),
comment=source_spot["remarks"],
sig="WWFF",
sig=ActivityName.WWFF,
sig_refs=[
ActivityRef(
id=source_spot["reference"],
sig="WWFF",
sig=ActivityName.WWFF,
name=source_spot["reference_name"],
latitude=source_spot["latitude"],
longitude=source_spot["longitude"],
@@ -52,7 +53,7 @@ class WWFF(HTTPSpotProvider):
return new_spots
def can_submit_spot(self, activity):
return activity == "WWFF"
return activity == ActivityName.WWFF
def submit_spot(self, spot, credentials):
# TODO: Implement. Spotting to WWFF should be possible, need to look up the Spotline docs or copy approach from
+4 -3
View File
@@ -3,6 +3,7 @@ from datetime import datetime
import pytz
from core.enums import Mode
from core.enums import ActivityName
from data.activity_ref import ActivityRef
from data.spot import Spot
from providers.spot.http_spot_provider import HTTPSpotProvider
@@ -35,11 +36,11 @@ class ZLOTA(HTTPSpotProvider):
freq=freq_hz,
mode=Mode.from_name(source_spot["mode"].upper().strip()),
comment=source_spot["comments"],
sig="ZLOTA",
sig=ActivityName.ZLOTA,
sig_refs=[
ActivityRef(
id=source_spot["reference"],
sig="ZLOTA",
sig=ActivityName.ZLOTA,
name=source_spot["name"],
)
],
@@ -52,7 +53,7 @@ class ZLOTA(HTTPSpotProvider):
return new_spots
def can_submit_spot(self, activity):
return activity == "ZLOTA"
return activity == ActivityName.ZLOTA
def submit_spot(self, spot, credentials):
# TODO: Implement. Spotting to ZLOTA is supported via POST, see https://ontheair.nz/api