Files
spothole/providers/alert/pota.py
T

57 lines
2.2 KiB
Python

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
class POTA(HTTPAlertProvider):
"""Alert provider for Parks on the Air"""
POLL_INTERVAL_SEC = 1800
ALERTS_URL = "https://api.pota.app/activation"
def __init__(self, provider_config):
super().__init__("POTA", 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():
# Convert to our alert format
alert = Alert(
source=self.name,
source_id=source_alert["scheduledActivitiesId"],
dx_calls=[source_alert["activator"].upper()],
freqs_modes=source_alert["frequencies"],
comment=source_alert["comments"],
sig=ActivityName.POTA,
sig_refs=[
ActivityRef(
id=source_alert["reference"],
sig=ActivityName.POTA,
name=source_alert["name"],
url=f"https://pota.app/#/park/{source_alert['reference']}",
)
],
start_time=datetime.strptime(
source_alert["startDate"] + source_alert["startTime"],
"%Y-%m-%d%H:%M",
)
.replace(tzinfo=pytz.UTC)
.timestamp(),
end_time=datetime.strptime(source_alert["endDate"] + source_alert["endTime"], "%Y-%m-%d%H:%M")
.replace(tzinfo=pytz.UTC)
.timestamp(),
)
# Add to our list, but exclude any old spots that POTA can sometimes give us where even the end time is
# in the past. Don't worry about de-duping, removing old alerts etc. at this point; other code will do
# that for us.
if alert.end_time and alert.end_time > datetime.now(pytz.UTC).timestamp():
new_alerts.append(alert)
return new_alerts