diff --git a/core/constants.py b/core/constants.py index 05a7b8d..17f8815 100644 --- a/core/constants.py +++ b/core/constants.py @@ -11,20 +11,22 @@ HTTP_HEADERS = {"User-Agent": SOFTWARE_NAME + ", v" + SOFTWARE_VERSION + " (oper # Special Interest Groups SIGS = [ - SIG(name="POTA", description="Parks on the Air", icon="tree"), - SIG(name="SOTA", description="Summits on the Air", icon="mountain-sun"), - SIG(name="WWFF", description="World Wide Flora & Fauna", icon="seedling"), - SIG(name="GMA", description="Global Mountain Activity", icon="person-hiking"), - SIG(name="WWBOTA", description="Worldwide Bunkers on the Air", icon="radiation"), - SIG(name="HEMA", description="HuMPs Excluding Marilyns Award", icon="mound"), - SIG(name="IOTA", description="Islands on the Air", icon="umbrella-beach"), - SIG(name="MOTA", description="Mills on the Air", icon="fan"), - SIG(name="ARLHS", description="Amateur Radio Lighthouse Society", icon="tower-observation"), - SIG(name="ILLW", description="International Lighthouse & Lightship Weekend", icon="tower-observation"), - SIG(name="SIOTA", description="Silos on the Air", icon="wheat-awn"), - SIG(name="WCA", description="World Castles Award", icon="chess-rook"), - SIG(name="ZLOTA", description="New Zealand on the Air", icon="kiwi-bird"), - SIG(name="KRMNPA", description="Keith Roget Memorial National Parks Award", icon="earth-oceania") + SIG(name="POTA", description="Parks on the Air", icon="tree", ref_regex=r"[A-Z]{2}\-\d+"), + SIG(name="SOTA", description="Summits on the Air", icon="mountain-sun", ref_regex=r"[A-Z0-9]{1,3}\/[A-Z]{2}\-\d+"), + SIG(name="WWFF", description="World Wide Flora & Fauna", icon="seedling", ref_regex=r"[A-Z0-9]{1,3}FF\-\d+"), + SIG(name="GMA", description="Global Mountain Activity", icon="person-hiking", ref_regex=r"[A-Z0-9]{1,3}\/[A-Z]{2}\-\d+"), + SIG(name="WWBOTA", description="Worldwide Bunkers on the Air", icon="radiation", ref_regex=r"B\/[A-Z0-9]{1,3}\-\d+"), + SIG(name="HEMA", description="HuMPs Excluding Marilyns Award", icon="mound", ref_regex=r"[A-Z0-9]{1,3}\/[A-Z]{3}\-\d+"), + SIG(name="IOTA", description="Islands on the Air", icon="umbrella-beach", ref_regex=r"[A-Z]{2}\-\d+"), + SIG(name="MOTA", description="Mills on the Air", icon="fan", ref_regex=r"X\d{4-6}"), + SIG(name="ARLHS", description="Amateur Radio Lighthouse Society", icon="tower-observation", ref_regex=r"[A-Z]{3}\-\d+"), + SIG(name="ILLW", description="International Lighthouse & Lightship Weekend", icon="tower-observation", ref_regex=r"[A-Z]{2}\d{4}"), + SIG(name="SIOTA", description="Silos on the Air", icon="wheat-awn", ref_regex=r"[A-Z]{2}\-[A-Z]{3}\d"), + SIG(name="WCA", description="World Castles Award", icon="chess-rook", ref_regex=r"[A-Z0-9]{1,3}\-\d+"), + SIG(name="ZLOTA", description="New Zealand on the Air", icon="kiwi-bird", ref_regex=r"ZL[A-Z]/[A-Z]{2}\-\d+"), + SIG(name="KRMNPA", description="Keith Roget Memorial National Parks Award", icon="earth-oceania", ref_regex=r""), + SIG(name="WAB", description="Worked All Britain", icon="table-cells-large", ref_regex=r"[A-Z]{2}[0-9]{2}"), + SIG(name="WAI", description="Worked All Ireland", icon="table-cells-large", ref_regex=r"[A-Z][0-9]{2}") ] # Modes. Note "DIGI" and "DIGITAL" are also supported but are normalised into "DATA". diff --git a/core/utils.py b/core/utils.py index 61b320e..a915325 100644 --- a/core/utils.py +++ b/core/utils.py @@ -7,8 +7,15 @@ def get_icon_for_sig(sig): return s.icon return "circle-question" +# Utility function to get the regex string for a SIG reference for a named SIG. If no match is found, None will be returned. +def get_ref_regex_for_sig(sig): + for s in SIGS: + if s.name == sig: + return s.ref_regex + return None + # Regex matching any SIG ANY_SIG_REGEX = r"(" + r"|".join(list(map(lambda p: p.name, SIGS))) + r")" # Regex matching any SIG reference -ANY_SIG_REF_REGEX = r"[\w\/]+\-\d+" \ No newline at end of file +ANY_XOTA_SIG_REF_REGEX = r"[\w\/]+\-\d+" \ No newline at end of file diff --git a/data/sig.py b/data/sig.py index 082425f..5d6e2d2 100644 --- a/data/sig.py +++ b/data/sig.py @@ -9,4 +9,6 @@ class SIG: description: str # Icon to use for it, from the Font Awesome set. This is fairly opinionated but is here to help the Spothole web UI # and Field Spotter. Does not include the "fa-" prefix. - icon: str \ No newline at end of file + icon: str + # Regex matcher for references, e.g. for POTA r"[A-Z]{2}\-\d+". + ref_regex: str \ No newline at end of file diff --git a/spotproviders/dxcluster.py b/spotproviders/dxcluster.py index 80e9bca..1220579 100644 --- a/spotproviders/dxcluster.py +++ b/spotproviders/dxcluster.py @@ -8,7 +8,7 @@ import pytz import telnetlib3 from core.constants import SIGS -from core.utils import ANY_SIG_REGEX, ANY_SIG_REF_REGEX, get_icon_for_sig +from core.utils import ANY_SIG_REGEX, ANY_XOTA_SIG_REF_REGEX, get_icon_for_sig, get_ref_regex_for_sig from data.spot import Spot from core.config import SERVER_OWNER_CALLSIGN from spotproviders.spot_provider import SpotProvider @@ -78,14 +78,19 @@ class DXCluster(SpotProvider): time=spot_datetime.timestamp()) # See if the comment looks like it contains a SIG (and optionally SIG reference). Currently, - # only one sig ref is supported. + # only one sig ref is supported. Note that this code is specifically in the DX Cluster class and + # not in the general "spot" infer_missing() method. Because we only support one SIG per spot + # at the moment (see issue #54), we don't want to risk e.g. a POTA spot with comment "WWFF GFF-0001" + # being converted into a WWFF spot. sig_match = re.search(r"(^|\W)" + ANY_SIG_REGEX + r"($|\W)", spot.comment, re.IGNORECASE) if sig_match: spot.sig = sig_match.group(2).upper() spot.icon = get_icon_for_sig(spot.sig) - sig_ref_match = re.search(r"(^|\W)" + spot.sig + r"($|\W)(" + ANY_SIG_REF_REGEX + r")($|\W)", spot.comment, re.IGNORECASE) - if sig_ref_match: - spot.sig_refs = [sig_ref_match.group(3).upper()] + ref_regex = get_ref_regex_for_sig(spot.sig) + if ref_regex: + sig_ref_match = re.search(r"(^|\W)" + spot.sig + r"($|\W)(" + ref_regex + r")($|\W)", spot.comment, re.IGNORECASE) + if sig_ref_match: + spot.sig_refs = [sig_ref_match.group(3).upper()] # Add to our list self.submit(spot)