import logging from datetime import datetime import pytz from alertproviders.http_alert_provider import HTTPAlertProvider from data.alert import Alert # Alert provider for Parks n Peaks class ParksNPeaks(HTTPAlertProvider): POLL_INTERVAL_SEC = 3600 ALERTS_URL = "http://parksnpeaks.org/api/ALERTS/" def __init__(self, provider_config): super().__init__(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 if " - " in source_alert["Location"]: split = source_alert["Location"].split(" - ") sig_ref = split[0] sig_ref_name = split[1] else: sig_ref = source_alert["WWFFID"] sig_ref_name = source_alert["Location"] start_time = datetime.strptime(source_alert["alTime"], "%Y-%m-%d %H:%M:%S").replace( tzinfo=pytz.UTC).timestamp() # Convert to our alert format alert = Alert(source=self.name, source_id=source_alert["alID"], dx_calls=[source_alert["CallSign"].upper()], freqs_modes=source_alert["Freq"] + " " + source_alert["MODE"], comment=source_alert["Comments"], sig=source_alert["Class"], sig_refs=[sig_ref], sig_refs_names=[sig_ref_name], start_time=start_time, is_dxpedition=False) # PNP supports a bunch of programs which should have different icons if alert.sig == "SiOTA": alert.icon = "wheat-awn" elif alert.sig == "ZLOTA": alert.icon = "kiwi-bird" elif alert.sig == "KRMNPA": alert.icon = "earth-oceania" elif alert.sig in ["POTA", "SOTA", "WWFF"]: # Don't care about an icon as this will be rejected anyway, we have better data from POTA/SOTA/WWFF direct alert.icon = "" else: # Unknown programme we've never seen before logging.warn( "PNP alert found with sig " + alert.sig + ", developer needs to add support for this and set an icon!") alert.icon = "question" # If this is POTA, SOTA or WWFF data we already have it through other means, so ignore. Otherwise, add to # the alert list. if alert.sig not in ["POTA", "SOTA", "WWFF"]: new_alerts.append(alert) return new_alerts