Allow alerts to have more than one DX callsign, and parse the "as CALL" fields from NG3K. Not yet working #38

This commit is contained in:
Ian Renton
2025-10-10 11:37:59 +01:00
parent 5c3adcdd4d
commit cc816d8662
7 changed files with 47 additions and 32 deletions

View File

@@ -1,3 +1,4 @@
import re
from datetime import datetime
import pytz
@@ -11,6 +12,7 @@ from data.alert import Alert
class NG3K(HTTPAlertProvider):
POLL_INTERVAL_SEC = 3600
ALERTS_URL = "https://www.ng3k.com/adxo.xml"
AS_CALL_PATTERN = re.compile("as ([a-z0-9/]+)", re.IGNORECASE)
def __init__(self, provider_config):
super().__init__(provider_config, self.ALERTS_URL, self.POLL_INTERVAL_SEC)
@@ -49,18 +51,26 @@ class NG3K(HTTPAlertProvider):
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]
# Sometimes the DX callsign is "real", sometimes you just get a prefix with the real working callsigns being
# provided in the "by" field. e.g. call="JW", by="By LA7XK as JW7XK, LA6VM as JW6VM, LA9DL as JW9DL". So
# if there are "as" callsigns in the "by" field, we extract them and replace the main call with them.
# TODO this doesn't work yet, debug
extra_parts = parts[5].split("; ")
by = extra_parts[0]
dx_calls = [parts[2].upper()]
match = self.AS_CALL_PATTERN.match(by)
if match:
dx_calls = [x.group(1) for x in re.finditer(self.AS_CALL_PATTERN, by)]
dx_country = parts[1]
qsl_info = parts[3]
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_calls=dx_calls,
dx_country=dx_country,
freqs_modes=bands + (("; " + modes) if modes != "" else ""),
comment=by + "; " + comment + "; " + qsl_info,