mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2025-10-27 08:49:27 +00:00
60 lines
2.2 KiB
Python
60 lines
2.2 KiB
Python
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
|