From e3d1607c869b5876d431bf3234605e65b9eb15fa Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Tue, 17 Dec 2024 23:11:05 -0800 Subject: [PATCH] enhance EU --- mesh_bot.py | 10 +++++----- modules/locationdata.py | 25 ++++++++++++------------- modules/locationdata_eu.py | 27 +++++++++++++++++++++++++++ modules/system.py | 2 +- 4 files changed, 45 insertions(+), 19 deletions(-) create mode 100644 modules/locationdata_eu.py diff --git a/mesh_bot.py b/mesh_bot.py index 85d17d2..1ddbd76 100755 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -282,9 +282,9 @@ def handle_wxalert(message_from_id, deviceID, message): location = get_node_location(message_from_id, deviceID) if "wxalert" in message: # Detailed weather alert - weatherAlert = getActiveWeatherAlertsDetail(str(location[0]), str(location[1])) + weatherAlert = getActiveWeatherAlertsDetailNOAA(str(location[0]), str(location[1])) else: - weatherAlert = getWeatherAlerts(str(location[0]), str(location[1])) + weatherAlert = getWeatherAlertsNOAA(str(location[0]), str(location[1])) if NO_ALERTS not in weatherAlert: weatherAlert = weatherAlert[0] @@ -680,10 +680,10 @@ def handle_wxc(message_from_id, deviceID, cmd): weather = get_wx_meteo(str(location[0]), str(location[1]), 1) elif not use_meteo_wxApi and "wxc" in cmd or use_metric: #logger.debug("System: Bot Returning NOAA API for weather metric") - weather = get_weather(str(location[0]), str(location[1]), 1) + weather = get_NOAAweather(str(location[0]), str(location[1]), 1) else: #logger.debug("System: Bot Returning NOAA API for weather imperial") - weather = get_weather(str(location[0]), str(location[1])) + weather = get_NOAAweather(str(location[0]), str(location[1])) return weather def handle_fema_alerts(message, message_from_id, deviceID): @@ -857,7 +857,7 @@ def handle_repeaterQuery(message_from_id, deviceID, channel_number): def handle_tide(message_from_id, deviceID, channel_number): location = get_node_location(message_from_id, deviceID, channel_number) - return get_tide(str(location[0]), str(location[1])) + return get_NOAAtide(str(location[0]), str(location[1])) def handle_moon(message_from_id, deviceID, channel_number): location = get_node_location(message_from_id, deviceID, channel_number) diff --git a/modules/locationdata.py b/modules/locationdata.py index 18f8540..5aafa91 100644 --- a/modules/locationdata.py +++ b/modules/locationdata.py @@ -154,9 +154,8 @@ def getArtSciRepeaters(lat=0, lon=0): else: msg = f"no results.. sorry" return msg - -def get_tide(lat=0, lon=0): +def get_NOAAtide(lat=0, lon=0): station_id = "" if float(lat) == 0 and float(lon) == 0: logger.error("Location:No GPS data, try sending location for tide") @@ -219,7 +218,7 @@ def get_tide(lat=0, lon=0): tide_table = tide_table[:-1] return tide_table -def get_weather(lat=0, lon=0, unit=0): +def get_NOAAweather(lat=0, lon=0, unit=0): # get weather report from NOAA for forecast detailed weather = "" if float(lat) == 0 and float(lon) == 0: @@ -263,7 +262,7 @@ def get_weather(lat=0, lon=0, unit=0): weather = weather[:-1] # get any alerts and return the count - alerts = getWeatherAlerts(lat, lon) + alerts = getWeatherAlertsNOAA(lat, lon) if alerts == ERROR_FETCHING_DATA or alerts == NO_DATA_NOGPS or alerts == NO_ALERTS: alert = "" @@ -333,7 +332,7 @@ def abbreviate_noaa(row): return line -def getWeatherAlerts(lat=0, lon=0, useDefaultLatLon=False): +def getWeatherAlertsNOAA(lat=0, lon=0, useDefaultLatLon=False): # get weather alerts from NOAA limited to ALERT_COUNT with the total number of alerts found alerts = "" if float(lat) == 0 and float(lon) == 0 and not useDefaultLatLon: @@ -381,27 +380,27 @@ def getWeatherAlerts(lat=0, lon=0, useDefaultLatLon=False): data = "\n".join(alerts.split("\n")[:numWxAlerts]), alert_num return data -wxAlertCache = "" -def alertBrodcast(): +wxAlertCacheNOAA = "" +def alertBrodcastNOAA(): # get the latest weather alerts and broadcast them if there are any - global wxAlertCache - currentAlert = getWeatherAlerts(latitudeValue, longitudeValue) + global wxAlertCacheNOAA + currentAlert = getWeatherAlertsNOAA(latitudeValue, longitudeValue) # check if any reason to discard the alerts if currentAlert == ERROR_FETCHING_DATA or currentAlert == NO_DATA_NOGPS: return False elif currentAlert == NO_ALERTS: - wxAlertCache = "" + wxAlertCacheNOAA = "" return False # broadcast the alerts send to wxBrodcastCh - elif currentAlert[0] not in wxAlertCache: + elif currentAlert[0] not in wxAlertCacheNOAA: # Check if the current alert is not in the weather alert cache logger.debug("Location:Broadcasting weather alerts") - wxAlertCache = currentAlert[0] + wxAlertCacheNOAA = currentAlert[0] return currentAlert return False -def getActiveWeatherAlertsDetail(lat=0, lon=0): +def getActiveWeatherAlertsDetailNOAA(lat=0, lon=0): # get the latest details of weather alerts from NOAA alerts = "" if float(lat) == 0 and float(lon) == 0: diff --git a/modules/locationdata_eu.py b/modules/locationdata_eu.py new file mode 100644 index 0000000..967270a --- /dev/null +++ b/modules/locationdata_eu.py @@ -0,0 +1,27 @@ +# helper functions to use location data for data outside US/north america +# K7MHI Kelly Keeton 2024 + +import json # pip install json +from geopy.geocoders import Nominatim # pip install geopy +import maidenhead as mh # pip install maidenhead +import requests # pip install requests +import bs4 as bs # pip install beautifulsoup4 +import xml.dom.minidom +from modules.log import * + +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') + return "not implemented yet" + +def get_wxUKgov(): + # get UK weather warnings + url = 'https://www.metoffice.gov.uk/weather/guides/rss' + return "not implemented yet" + +def get_floodEKgov(): + # get UK flood warnings + url = 'https://environment.data.gov.uk/flood-widgets/rss-feeds.html' + return "not implemented yet" \ No newline at end of file diff --git a/modules/system.py b/modules/system.py index d7b62de..ecec45b 100644 --- a/modules/system.py +++ b/modules/system.py @@ -671,7 +671,7 @@ def handleWxBroadcast(deviceID=1): return False # check for alerts - alert = alertBrodcast() + alert = alertBrodcastNOAA() if alert: msg = f"🚨 {alert[1]} EAS ALERTs: {alert[0]}" if isinstance(wxAlertBroadcastChannel, list):