Files
spothole/alertproviders/ng3k.py
2025-10-09 17:03:42 +01:00

74 lines
2.8 KiB
Python

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 NG3K DXpedition list
class NG3K(HTTPAlertProvider):
POLL_INTERVAL_SEC = 3600
ALERTS_URL = "https://www.ng3k.com/adxo.xml"
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:
# Deal with "the format"...
parts = source_alert.description.split(" --\n")
start_string = parts[0].split("-")[0]
end_string = parts[0].split("-")[1]
end_year = end_string.split(", ")[1].strip()
if ", " in start_string:
start_year = start_string.split(", ")[1].strip()
start_mon = start_string.split(", ")[0][0:3].strip()
start_day = start_string.split(", ")[0][4:].strip()
else:
start_year = end_year
start_mon = start_string[0:3].strip()
start_day = start_string[4:].strip()
if " " in end_string.split(", ")[0]:
end_mon = end_string.split(", ")[0].split(" ")[0].strip()
end_day = end_string.split(", ")[0].split(" ")[1].strip()
else:
end_day = end_string.split(", ")[0].strip()
end_mon = start_mon
start_timestamp = datetime.strptime(start_year + " " + start_mon + " " + start_day, "%Y %b %d").replace(
tzinfo=pytz.UTC).timestamp()
end_timestamp = datetime.strptime(end_year + " " + end_mon + " " + end_day + " 23:59", "%Y %b %d %H:%M").replace(
tzinfo=pytz.UTC).timestamp()
dx_country = parts[1]
dx_call = parts[2]
qsl_info = parts[3]
extra_parts = parts[5].split("; ")
by = extra_parts[0]
bands = extra_parts[1]
modes = extra_parts[2] if len(extra_parts) > 3 else ""
comment = extra_parts[-1]
# Convert to our alert format
alert = Alert(source=self.name,
dx_call=dx_call.upper(),
dx_country=dx_country,
freqs_modes=bands + (("; " + modes) if modes != "" else ""),
comment=by + "; " + comment + "; " + qsl_info,
icon="globe-africa",
start_time=start_timestamp,
end_time=end_timestamp)
# Add to our list.
new_alerts.append(alert)
return new_alerts