diff --git a/alertproviders/wota.py b/alertproviders/wota.py new file mode 100644 index 0000000..31dcf95 --- /dev/null +++ b/alertproviders/wota.py @@ -0,0 +1,59 @@ +import re +from datetime import datetime + +import pytz +from rss_parser import RSSParser + +from alertproviders.http_alert_provider import HTTPAlertProvider +from data.alert import Alert + + +# Alert provider for Wainwrights on the Air +class WOTA(HTTPAlertProvider): + POLL_INTERVAL_SEC = 3600 + ALERTS_URL = "https://www.wota.org.uk/alerts_rss.php" + RSS_DATE_TIME_FORMAT = "%a, %d %b %Y %H:%M:%S %z" + + 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 = [] + rss = RSSParser.parse(http_response.content.decode()) + # Iterate through source data + for source_alert in rss.channel.items: + # Pick apart the title + title_split = source_alert.title.split(" on ") + dx_call = title_split[0] + ref = None + ref_name = None + if len(title_split) > 1: + ref_split = title_split[1].split(" - ") + ref = ref_split[0] + if len(ref_split) > 1: + ref_name = ref_split[1] + + # Pick apart the description + desc_split = source_alert.description.split(". ") + freqs_modes = desc_split[0].replace("Frequencies/modes:", "").strip() + comment = None + if len(desc_split) > 1: + comment = desc_split[1].strip() + + time = datetime.strptime(source_alert.pub_date.content, self.RSS_DATE_TIME_FORMAT).astimezone(pytz.UTC) + + # Convert to our alert format + alert = Alert(source=self.name, + source_id=source_alert.guid.content, + dx_calls=[dx_call], + freqs_modes=freqs_modes, + comment=comment, + sig="WOTA", + sig_refs=[ref] if ref else [], + sig_refs_names=[ref_name] if ref_name else [], + icon="mound", + start_time=time.timestamp()) + + # Add to our list. + new_alerts.append(alert) + return new_alerts diff --git a/spotproviders/wota.py b/spotproviders/wota.py new file mode 100644 index 0000000..39ed3bc --- /dev/null +++ b/spotproviders/wota.py @@ -0,0 +1,23 @@ +import re + +from rss_parser import RSSParser + +from spotproviders.http_spot_provider import HTTPSpotProvider + + +# Spot provider for Wainwrights on the Air +class WOTA(HTTPSpotProvider): + POLL_INTERVAL_SEC = 120 + SPOTS_URL = "https://www.wota.org.uk/spots_rss.php" + + def __init__(self, provider_config): + super().__init__(provider_config, self.SPOTS_URL, self.POLL_INTERVAL_SEC) + + def http_response_to_spots(self, http_response): + new_spots = [] + rss = RSSParser.parse(http_response.content.decode()) + # Iterate through source data + for source_alert in rss.channel.items: + break + # TODO: Need to see a live spot to know what this feed looks like + return new_spots