mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-09-25 08:44:33 +00:00
67 lines
2.7 KiB
Python
67 lines
2.7 KiB
Python
import logging
|
|
from datetime import datetime
|
|
|
|
import pytz
|
|
|
|
from core.activity_utils import get_activity_by_name
|
|
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()
|
|
)
|
|
|
|
# We can only add a reference if we know the activity it's for
|
|
found_activity = get_activity_by_name(activity)
|
|
activities = []
|
|
activity_refs = []
|
|
if found_activity is not None:
|
|
activities = [found_activity.name]
|
|
activity_refs = [ActivityRef(id=ref_id, activity=found_activity.name, 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"],
|
|
activities=activities,
|
|
activity_refs=activity_refs,
|
|
start_time=start_time,
|
|
)
|
|
|
|
# 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
|