diff --git a/mesh_bot.py b/mesh_bot.py index 1ddbd76..938fb6a 100755 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -277,7 +277,10 @@ def handle_motd(message, message_from_id, isDM): def handle_wxalert(message_from_id, deviceID, message): if use_meteo_wxApi: - return "wxalert is not supported" + if useEUalerts: + return get_govUK_alerts() + else: + return "wxalert is not supported" else: location = get_node_location(message_from_id, deviceID) if "wxalert" in message: diff --git a/modules/locationdata_eu.py b/modules/locationdata_eu.py index b58749c..4e618b7 100644 --- a/modules/locationdata_eu.py +++ b/modules/locationdata_eu.py @@ -12,14 +12,19 @@ from modules.log import * trap_list_location_eu = ("ukalert", "ukwx", "ukflood") def get_govUK_alerts(): - # get UK weather alerts - url = 'https://www.gov.uk/alerts' - response = requests.get(url) - soup = bs.BeautifulSoup(response.text, 'html.parser') - # the alerts are in

- alert = soup.find('h2', class_='govuk-heading-m', id='alert-status') + try: + # get UK.gov alerts + url = 'https://www.gov.uk/alerts' + response = requests.get(url) + soup = bs.BeautifulSoup(response.text, 'html.parser') + # the alerts are in

+ alert = soup.find('h2', class_='govuk-heading-m', id='alert-status') + except Exception as e: + logger.warning("Error getting UK alerts: " + str(e)) + return "System: Error getting UK alerts" + if alert: - return alert.get_text(strip=True) + return "🚨" + alert.get_text(strip=True) else: return "No alerts" diff --git a/modules/settings.py b/modules/settings.py index 4765ce5..5fc62f6 100644 --- a/modules/settings.py +++ b/modules/settings.py @@ -155,7 +155,7 @@ try: latitudeValue = config['location'].getfloat('lat', 48.50) longitudeValue = config['location'].getfloat('lon', -123.0) use_meteo_wxApi = config['location'].getboolean('UseMeteoWxAPI', False) # default False use NOAA - includeEUalerts = config['location'].getboolean('includeEUalerts', False) # default False + useEUalerts = config['location'].getboolean('includeEUalerts', False) # default False use_metric = config['location'].getboolean('useMetric', False) # default Imperial units forecastDuration = config['location'].getint('NOAAforecastDuration', 4) # NOAA forcast days numWxAlerts = config['location'].getint('NOAAalertCount', 2) # default 2 alerts diff --git a/modules/system.py b/modules/system.py index 0559f82..7dcb4bf 100644 --- a/modules/system.py +++ b/modules/system.py @@ -74,7 +74,7 @@ if location_enabled: from modules.locationdata import * # from the spudgunman/meshing-around repo trap_list = trap_list + trap_list_location # items tide, whereami, wxc, wx help_message = help_message + ", whereami, wx, wxc, rlist" - if includeEUalerts: + if useEUalerts: from modules.locationdata_eu import * # from the spudgunman/meshing-around repo trap_list = trap_list + trap_list_location_eu #help_message = help_message + ", ukalert, ukwx, ukflood"