diff --git a/providers/alert/wota.py b/providers/alert/wota.py index 66d9364..83a1d22 100644 --- a/providers/alert/wota.py +++ b/providers/alert/wota.py @@ -1,3 +1,4 @@ +import logging from datetime import datetime from typing import cast @@ -9,6 +10,8 @@ from data.alert import Alert from data.sig_ref import SIGRef from providers.alert.http_alert_provider import HTTPAlertProvider +logger = logging.getLogger(__name__) + class WOTA(HTTPAlertProvider): """Alert provider for Wainwrights on the Air""" @@ -34,22 +37,30 @@ class WOTA(HTTPAlertProvider): continue # Pick apart the title - title_split = source_alert.title.split(" on ") - dx_call = title_split[0] + dx_call = None ref = None ref_name = None - if len(title_split) > 1: - ref_split = title_split[1].split(" - ") - ref = str(ref_split[0]) - if len(ref_split) > 1: - ref_name = str(ref_split[1]) + try: + title_split = source_alert.title.split(" on ") + dx_call = title_split[0] + if len(title_split) > 1: + ref_split = title_split[1].split(" - ") + ref = str(ref_split[0]) + if len(ref_split) > 1: + ref_name = str(ref_split[1]) + except Exception: + logger.warning(f"Could not parse WOTA alert title: {source_alert.description}") # 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() + freqs_modes = None + try: + desc_split = source_alert.description.split(". ") + freqs_modes = desc_split[0].replace("Frequencies/modes:", "").strip() + if len(desc_split) > 1: + comment = desc_split[1].strip() + except Exception: + logger.warning(f"Could not parse WOTA alert description: {source_alert.description}") time = datetime.strptime(source_alert.pub_date.content, self.RSS_DATE_TIME_FORMAT).astimezone(pytz.UTC) diff --git a/providers/spot/wota.py b/providers/spot/wota.py index f85de2b..a66b813 100644 --- a/providers/spot/wota.py +++ b/providers/spot/wota.py @@ -39,36 +39,39 @@ class WOTA(HTTPSpotProvider): continue # Pick apart the title - title_split = source_spot.title.split(" on ") - dx_call = title_split[0] + dx_call = None ref = None ref_name = None - if len(title_split) > 1: - ref_split = title_split[1].split(" - ") - ref = str(ref_split[0]) - if len(ref_split) > 1: - ref_name = str(ref_split[1]) + try: + title_split = source_spot.title.split(" on ") + dx_call = title_split[0] + if len(title_split) > 1: + ref_split = title_split[1].split(" - ") + ref = str(ref_split[0]) + if len(ref_split) > 1: + ref_name = str(ref_split[1]) + except Exception: + logger.warning(f"Could not parse WOTA spot title: {source_spot.title}") # Pick apart the description - desc_split = source_spot.description.split(". ") - freq_mode = desc_split[0].replace("Frequencies/modes:", "").strip() - freq_mode_split = re.split(r"[\-\s]+", freq_mode) freq_hz = None mode = None + comment = None + spotter = None try: + desc_split = source_spot.description.split(". ") + freq_mode = desc_split[0].replace("Frequencies/modes:", "").strip() + freq_mode_split = re.split(r"[\-\s]+", freq_mode) freq_hz = float(freq_mode_split[0].replace("'", ".")) * 1000000 if len(freq_mode_split) > 1: mode = freq_mode_split[1].upper() - except ValueError: - # Something wrong with parsing frequency and mode, bail out - pass - comment = None - if len(desc_split) > 1: - comment = desc_split[1].strip() - spotter = None - if len(desc_split) > 2: - spotter = desc_split[2].replace("Spotted by ", "").replace(".", "").upper().strip() + if len(desc_split) > 1: + comment = desc_split[1].strip() + if len(desc_split) > 2: + spotter = desc_split[2].replace("Spotted by ", "").replace(".", "").upper().strip() + except Exception: + logger.warning(f"Could not parse WOTA spot description: {source_spot.description}") time = datetime.strptime(source_spot.pub_date.content, self.RSS_DATE_TIME_FORMAT).astimezone(pytz.UTC) diff --git a/templates/add_spot.html b/templates/add_spot.html index 4c7f4ce..e63b4eb 100644 --- a/templates/add_spot.html +++ b/templates/add_spot.html @@ -76,7 +76,7 @@ - + diff --git a/templates/alerts.html b/templates/alerts.html index dd010e1..3dadaaf 100644 --- a/templates/alerts.html +++ b/templates/alerts.html @@ -84,7 +84,7 @@ - + diff --git a/templates/bands.html b/templates/bands.html index f3d6fcd..7253036 100644 --- a/templates/bands.html +++ b/templates/bands.html @@ -76,8 +76,8 @@ - - + + diff --git a/templates/base.html b/templates/base.html index 2a74886..3b3aeb7 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,6 +1,6 @@ {% extends "skeleton.html" %} {% block head_extra %} - + @@ -15,10 +15,10 @@ window.fetchEventSource = fetchEventSource; - - - - + + + + {% end %} {% block body %}