mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-09-20 14:27:42 +00:00
Refactor activity names to use an enum instead of a string to avoid typos #147
This commit is contained in:
@@ -3,6 +3,7 @@ from datetime import datetime, timedelta
|
||||
import pytz
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
from core.enums import ActivityName
|
||||
from data.activity_ref import ActivityRef
|
||||
from data.alert import Alert
|
||||
from providers.alert.http_alert_provider import HTTPAlertProvider
|
||||
@@ -55,8 +56,8 @@ class BOTA(HTTPAlertProvider):
|
||||
alert = Alert(
|
||||
source=self.name,
|
||||
dx_calls=[dx_call],
|
||||
sig="BOTA",
|
||||
sig_refs=[ActivityRef(id=ref_name, sig="BOTA")],
|
||||
sig=ActivityName.BOTA,
|
||||
sig_refs=[ActivityRef(id=ref_name, sig=ActivityName.BOTA)],
|
||||
start_time=date_time.timestamp(),
|
||||
)
|
||||
|
||||
|
||||
@@ -2,6 +2,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
|
||||
@@ -34,11 +35,11 @@ class Hamsat(HTTPAlertProvider):
|
||||
dx_calls=[source_alert["callsign"].upper()],
|
||||
freqs_modes=freqs_modes,
|
||||
comment=source_alert["comment"],
|
||||
sig="Satellite",
|
||||
sig=ActivityName.SATELLITE,
|
||||
# Fudge an activity ref to provide the remaining bits of data we need: the satellite and the operator's grid
|
||||
sig_refs=[
|
||||
ActivityRef(
|
||||
sig="Satellite",
|
||||
sig=ActivityName.SATELLITE,
|
||||
id=f"{source_alert['satellite']['name']} from {source_alert['grids'][0]}",
|
||||
)
|
||||
],
|
||||
|
||||
@@ -6,6 +6,7 @@ import pytz
|
||||
from rss_parser import Parser
|
||||
from rss_parser.models.rss import RSS
|
||||
|
||||
from core.enums import ActivityName
|
||||
from data.alert import Alert
|
||||
from providers.alert.http_alert_provider import HTTPAlertProvider
|
||||
|
||||
@@ -88,7 +89,7 @@ class NG3K(HTTPAlertProvider):
|
||||
comment=f"{by}; {comment}; {qsl_info}",
|
||||
start_time=start_timestamp,
|
||||
end_time=end_timestamp,
|
||||
sig="DXpedition",
|
||||
sig=ActivityName.DXPEDITION,
|
||||
)
|
||||
|
||||
# Add to our list.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -2,6 +2,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
|
||||
@@ -27,11 +28,11 @@ class POTA(HTTPAlertProvider):
|
||||
dx_calls=[source_alert["activator"].upper()],
|
||||
freqs_modes=source_alert["frequencies"],
|
||||
comment=source_alert["comments"],
|
||||
sig="POTA",
|
||||
sig=ActivityName.POTA,
|
||||
sig_refs=[
|
||||
ActivityRef(
|
||||
id=source_alert["reference"],
|
||||
sig="POTA",
|
||||
sig=ActivityName.POTA,
|
||||
name=source_alert["name"],
|
||||
url=f"https://pota.app/#/park/{source_alert['reference']}",
|
||||
)
|
||||
|
||||
@@ -3,6 +3,7 @@ import re
|
||||
from icalendar import Event
|
||||
|
||||
from core.enums import Continent
|
||||
from core.enums import ActivityName
|
||||
from data.alert import Alert
|
||||
from providers.alert.ical_alert_provider import ICALAlertProvider
|
||||
|
||||
@@ -69,7 +70,7 @@ class RSGBICALAlertProvider(ICALAlertProvider):
|
||||
comment=summary,
|
||||
start_time=start_timestamp,
|
||||
end_time=end_timestamp,
|
||||
sig="Contest",
|
||||
sig=ActivityName.CONTEST,
|
||||
)
|
||||
|
||||
return alert
|
||||
|
||||
@@ -2,6 +2,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
|
||||
@@ -33,11 +34,11 @@ class SOTA(HTTPAlertProvider):
|
||||
dx_names=[source_alert["activatorName"].upper()],
|
||||
freqs_modes=source_alert["frequency"],
|
||||
comment=source_alert["comments"],
|
||||
sig="SOTA",
|
||||
sig=ActivityName.SOTA,
|
||||
sig_refs=[
|
||||
ActivityRef(
|
||||
id=f"{source_alert['associationCode']}/{source_alert['summitCode']}",
|
||||
sig="SOTA",
|
||||
sig=ActivityName.SOTA,
|
||||
name=summit_name,
|
||||
activation_score=summit_points,
|
||||
)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from icalendar import Event
|
||||
|
||||
from core.enums import ActivityName
|
||||
from data.alert import Alert
|
||||
from providers.alert.ical_alert_provider import ICALAlertProvider
|
||||
|
||||
@@ -34,7 +35,7 @@ class WA7BNM(ICALAlertProvider):
|
||||
url=url,
|
||||
start_time=start_timestamp,
|
||||
end_time=end_timestamp,
|
||||
sig="Contest",
|
||||
sig=ActivityName.CONTEST,
|
||||
)
|
||||
|
||||
return alert
|
||||
|
||||
@@ -7,6 +7,7 @@ import pytz
|
||||
from rss_parser import Parser as RSSParser
|
||||
from rss_parser.models.rss import RSS
|
||||
|
||||
from core.enums import ActivityName
|
||||
from data.activity_ref import ActivityRef
|
||||
from data.alert import Alert
|
||||
from providers.alert.http_alert_provider import HTTPAlertProvider
|
||||
@@ -74,7 +75,7 @@ class WOTA(HTTPAlertProvider):
|
||||
dx_calls=[dx_call],
|
||||
freqs_modes=freqs_modes,
|
||||
comment=comment,
|
||||
sig_refs=[ActivityRef(id=ref, sig="WOTA", name=ref_name)] if ref else [],
|
||||
sig_refs=[ActivityRef(id=ref, sig=ActivityName.WOTA, name=ref_name)] if ref else [],
|
||||
start_time=time.timestamp(),
|
||||
)
|
||||
|
||||
|
||||
@@ -2,6 +2,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
|
||||
@@ -27,8 +28,8 @@ class WWFF(HTTPAlertProvider):
|
||||
dx_calls=[source_alert["activator_call"].upper()],
|
||||
freqs_modes=f"{source_alert['band']} {source_alert['mode']}",
|
||||
comment=source_alert["remarks"],
|
||||
sig="WWFF",
|
||||
sig_refs=[ActivityRef(id=source_alert["reference"], sig="WWFF")],
|
||||
sig=ActivityName.WWFF,
|
||||
sig_refs=[ActivityRef(id=source_alert["reference"], sig=ActivityName.WWFF)],
|
||||
start_time=datetime.strptime(source_alert["utc_start"], "%Y-%m-%d %H:%M:%S")
|
||||
.replace(tzinfo=pytz.UTC)
|
||||
.timestamp(),
|
||||
|
||||
Reference in New Issue
Block a user