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
+13 -12
View File
@@ -3,6 +3,7 @@ from datetime import datetime
import pytz
from core.enums import ActivityName
from data.activity_ref import ActivityRef
from data.alert import Alert
from providers.alert.http_alert_provider import HTTPAlertProvider
@@ -39,7 +40,7 @@ class ParksNPeaks(HTTPAlertProvider):
activity_refs = []
# PnP can give us an alert of class "QRP" which is the only one that's not a real activity in Spothole's
# list, so mask this out if we got it.
if activity != "QRP":
if activity != ActivityName.QRP:
activity_refs = [ActivityRef(id=ref_id, sig=activity, name=ref_name)]
# Convert to our alert format
@@ -56,22 +57,22 @@ class ParksNPeaks(HTTPAlertProvider):
# Log a warning for the developer if PnP gives us an unknown programme we've never seen before
if activity and activity not in [
"POTA",
"SOTA",
"WWFF",
"HEMA",
"SIOTA",
"ZLOTA",
"KRMNPA",
"SANPCPA",
"LLOTA",
"QRP",
ActivityName.POTA,
ActivityName.SOTA,
ActivityName.WWFF,
ActivityName.HEMA,
ActivityName.SIOTA,
ActivityName.ZLOTA,
ActivityName.KRMNPA,
ActivityName.SANPCPA,
ActivityName.LLOTA,
ActivityName.QRP,
]:
logger.warning(f"PNP alert found with activity {activity}, developer needs to add support for this!")
# If this is POTA, SOTA or WWFF data we already have it through other means, so ignore. Otherwise, add to
# the alert list. Note that while ZLOTA has its own spots API, it doesn't have its own alerts API. So that
# means the PnP *spot* provider rejects ZLOTA spots here, but the PnP *alerts* provider here allows ZLOTA.
if activity not in ["POTA", "SOTA", "WWFF"]:
if activity not in [ActivityName.POTA, ActivityName.SOTA, ActivityName.WWFF]:
new_alerts.append(alert)
return new_alerts