mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-09-20 14:27:42 +00:00
75 lines
2.9 KiB
Python
75 lines
2.9 KiB
Python
import logging
|
|
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
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class ParksNPeaks(HTTPAlertProvider):
|
|
"""Alert provider for Parks n Peaks"""
|
|
|
|
POLL_INTERVAL_SEC = 1800
|
|
ALERTS_URL = "https://parksnpeaks.org/api/ALERTS/"
|
|
|
|
def __init__(self, provider_config):
|
|
super().__init__("ParksNPeaks", provider_config, self.ALERTS_URL, self.POLL_INTERVAL_SEC)
|
|
|
|
def _http_response_to_alerts(self, http_response):
|
|
new_alerts = []
|
|
# Iterate through source data
|
|
for source_alert in http_response.json():
|
|
# Calculate some things
|
|
activity = source_alert["Class"].upper()
|
|
if " - " in source_alert["Location"]:
|
|
split = source_alert["Location"].split(" - ")
|
|
ref_id = split[0]
|
|
ref_name = split[1]
|
|
else:
|
|
ref_id = source_alert["WWFFID"]
|
|
ref_name = source_alert["Location"]
|
|
start_time = (
|
|
datetime.strptime(source_alert["alTime"], "%Y-%m-%d %H:%M:%S").replace(tzinfo=pytz.UTC).timestamp()
|
|
)
|
|
|
|
activity_refs = [ActivityRef(id=ref_id, sig=activity, name=ref_name)]
|
|
|
|
# Convert to our alert format
|
|
alert = Alert(
|
|
source=self.name,
|
|
source_id=source_alert["alID"],
|
|
dx_calls=[source_alert["CallSign"].upper()],
|
|
freqs_modes=f"{source_alert['Freq']} {source_alert['MODE']}",
|
|
comment=source_alert["Comments"],
|
|
sig=activity,
|
|
sig_refs=activity_refs,
|
|
start_time=start_time,
|
|
)
|
|
|
|
# Log a warning for the developer if PnP gives us an unknown programme we've never seen before
|
|
if activity and activity not in [
|
|
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 [ActivityName.POTA, ActivityName.SOTA, ActivityName.WWFF]:
|
|
new_alerts.append(alert)
|
|
return new_alerts
|