From 5079c67f6269539a23d2484192f24e9e49b64a3d Mon Sep 17 00:00:00 2001 From: sodoku Date: Sun, 12 Jan 2025 13:26:34 +0100 Subject: [PATCH 1/2] enable NINA alerts for Germany --- config.template | 4 ++++ mesh_bot.py | 3 +++ modules/globalalert.py | 28 ++++++++++++++++++++++++++-- modules/settings.py | 2 ++ modules/system.py | 12 ++++++++++++ 5 files changed, 47 insertions(+), 2 deletions(-) diff --git a/config.template b/config.template index bd5cac3..f3c281b 100644 --- a/config.template +++ b/config.template @@ -147,6 +147,10 @@ ignoreFEMAtest = True # find your SAME https://www.weather.gov/nwr/counties mySAME = 053029,053073 enableGBalerts = False +enableDEalerts = False +# comma separated list of regional codes trigger local alert. +# find your regional codet at https://www.xrepository.de/api/xrepository/urn:de:bund:destatis:bevoelkerungsstatistik:schluessel:rs_2021-07-31/download/Regionalschl_ssel_2021-07-31.json +myRegionalKeys = 110000000000,120510000000 # Satalite Pass Prediction # Register for free API https://www.n2yo.com/login/ diff --git a/mesh_bot.py b/mesh_bot.py index d2ff88a..820df01 100755 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -694,6 +694,9 @@ def handle_wxc(message_from_id, deviceID, cmd): def handle_emergency_alerts(message, message_from_id, deviceID): location = get_node_location(message_from_id, deviceID) + if enableDEalerts: + # nina Alerts + return get_nina_alerts() if enableGBalerts: # UK Alerts return get_govUK_alerts(str(location[0]), str(location[1])) diff --git a/modules/globalalert.py b/modules/globalalert.py index 75f74f3..5acf989 100644 --- a/modules/globalalert.py +++ b/modules/globalalert.py @@ -27,7 +27,31 @@ def get_govUK_alerts(shortAlerts=False): return "🚨" + alert.get_text(strip=True) else: return NO_ALERTS - + +def get_nina_alerts(): + try: + # get api.bund.dev alerts + alerts = [] + + for regionalKey in myRegionalKeys: + + url = ( + "https://nina.api.proxy.bund.dev/api31/dashboard/" + regionalKey + ".json" + ) + response = requests.get(url) + data = response.json() + + + for item in data: + title = item["i18nTitle"]["de"] + alerts.append(f"🚨 {title}") + + + return "\n".join(alerts) if alerts else NO_ALERTS + + except Exception as e: + logger.warning("Error getting NINA alerts: " + str(e)) + return NO_ALERTS def get_wxUKgov(): # get UK weather warnings @@ -57,4 +81,4 @@ def get_floodUKgov(): # get UK flood warnings url = 'https://environment.data.gov.uk/flood-widgets/rss/feed-England.xml' - return NO_ALERTS \ No newline at end of file + return NO_ALERTS diff --git a/modules/settings.py b/modules/settings.py index 73af4a7..be332d2 100644 --- a/modules/settings.py +++ b/modules/settings.py @@ -165,8 +165,10 @@ try: emergencyAlertBrodcastEnabled = config['location'].getboolean('eAlertBroadcastEnabled', False) # default False wxAlertBroadcastEnabled = config['location'].getboolean('wxAlertBroadcastEnabled', False) # default False enableGBalerts = config['location'].getboolean('enableGBalerts', False) # default False + enableDEalerts = config['location'].getboolean('enableDEalerts', False) # default False wxAlertsEnabled = config['location'].getboolean('NOAAalertsEnabled', True) # default True mySAME = config['location'].get('mySAME', '').split(',') # default empty + myRegionalKeys = config['location'].get('myRegionalKeys', '110000000000').split(',') # default city Berlin forecastDuration = config['location'].getint('NOAAforecastDuration', 4) # NOAA forcast days numWxAlerts = config['location'].getint('NOAAalertCount', 2) # default 2 alerts ipawsPIN = config['location'].get('ipawsPIN', '000000') # default 000000 diff --git a/modules/system.py b/modules/system.py index 7caea4b..1cd65ec 100644 --- a/modules/system.py +++ b/modules/system.py @@ -671,6 +671,7 @@ def handleMultiPing(nodeID=0, deviceID=1): def handleAlertBroadcast(deviceID=1): alertUk = NO_ALERTS + alertDe = NO_ALERTS alertFema = NO_ALERTS wxAlert = NO_ALERTS # only allow API call every 20 minutes @@ -686,6 +687,8 @@ def handleAlertBroadcast(deviceID=1): alertWx = alertBrodcastNOAA() if emergencyAlertBrodcastEnabled: + if enableDEalerts: + alertDe = get_nina_alerts() if enableGBalerts: alertUk = get_govUK_alerts() else: @@ -700,6 +703,7 @@ def handleAlertBroadcast(deviceID=1): femaAlert = alertFema ukAlert = alertUk + deAlert = alertDe if emergencyAlertBrodcastEnabled: if NO_ALERTS not in femaAlert and ERROR_FETCHING_DATA not in femaAlert: @@ -716,6 +720,14 @@ def handleAlertBroadcast(deviceID=1): else: send_message(ukAlert, emergencyAlertBroadcastCh, 0, deviceID) return True + + if NO_ALERTS not in deAlert: + if isinstance(emergencyAlertBroadcastCh, list): + for channel in emergencyAlertBroadcastCh: + send_message(ukAlert, int(channel), 0, deviceID) + else: + send_message(ukAlert, emergencyAlertBroadcastCh, 0, deviceID) + return True # pause for 10 seconds time.sleep(10) From 12d94fb0dcbc01de0f4e35550e61dcf4e5f333a7 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Sun, 12 Jan 2025 13:22:30 -0800 Subject: [PATCH 2/2] NINA alerts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit @sodoku 👀 branch for testing new alerts --- config.template | 14 ++++++++++---- modules/globalalert.py | 14 +++----------- modules/settings.py | 2 +- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/config.template b/config.template index fa71231..7cefbfe 100644 --- a/config.template +++ b/config.template @@ -134,27 +134,33 @@ UseMeteoWxAPI = False # NOAA Hydrology unique identifiers, LID or USGS ID riverListDefault = -# EAS Alert Broadcast +# NOAA EAS Alert Broadcast wxAlertBroadcastEnabled = False # EAS Alert Broadcast Channels wxAlertBroadcastCh = 2 # Add extra location to the weather alert enableExtraLocationWx = False -# Goverment IPAWS/CAP Alert Broadcast +# Goverment Alert Broadcast defaults to FEMA IPAWS eAlertBroadcastEnabled = False -# Goverment Emergency IPAWS/CAP Alert Broadcast Channels +# Goverment Alert Broadcast Channels eAlertBroadcastCh = 2 + +# FEMA Alert Broadcast Settings # Ignore any headline that includes the word Test ignoreFEMAtest = True # comma separated list of codes (e.g., SAME,FIPS,ZIP) trigger local alert. # find your SAME https://www.weather.gov/nwr/counties mySAME = 053029,053073 + +# Use UK Alert Broadcast Data enableGBalerts = False + +# Use DE Alert Broadcast Data enableDEalerts = False # comma separated list of regional codes trigger local alert. # find your regional codet at https://www.xrepository.de/api/xrepository/urn:de:bund:destatis:bevoelkerungsstatistik:schluessel:rs_2021-07-31/download/Regionalschl_ssel_2021-07-31.json -myRegionalKeys = 110000000000,120510000000 +myRegionalKeysDE = 110000000000,120510000000 # Satalite Pass Prediction # Register for free API https://www.n2yo.com/login/ diff --git a/modules/globalalert.py b/modules/globalalert.py index 5acf989..9589d48 100644 --- a/modules/globalalert.py +++ b/modules/globalalert.py @@ -32,25 +32,17 @@ def get_nina_alerts(): try: # get api.bund.dev alerts alerts = [] - - for regionalKey in myRegionalKeys: - - url = ( - "https://nina.api.proxy.bund.dev/api31/dashboard/" + regionalKey + ".json" - ) + for regionalKey in myRegionalKeysDE: + url = ("https://nina.api.proxy.bund.dev/api31/dashboard/" + regionalKey + ".json") response = requests.get(url) data = response.json() - for item in data: title = item["i18nTitle"]["de"] alerts.append(f"🚨 {title}") - - return "\n".join(alerts) if alerts else NO_ALERTS - except Exception as e: - logger.warning("Error getting NINA alerts: " + str(e)) + logger.warning("Error getting NINA DE alerts: " + str(e)) return NO_ALERTS def get_wxUKgov(): diff --git a/modules/settings.py b/modules/settings.py index b287b0a..0e7af76 100644 --- a/modules/settings.py +++ b/modules/settings.py @@ -244,7 +244,7 @@ try: enableDEalerts = config['location'].getboolean('enableDEalerts', False) # default False wxAlertsEnabled = config['location'].getboolean('NOAAalertsEnabled', True) # default True mySAME = config['location'].get('mySAME', '').split(',') # default empty - myRegionalKeys = config['location'].get('myRegionalKeys', '110000000000').split(',') # default city Berlin + myRegionalKeysDE = config['location'].get('myRegionalKeysDE', '110000000000').split(',') # default city Berlin forecastDuration = config['location'].getint('NOAAforecastDuration', 4) # NOAA forcast days numWxAlerts = config['location'].getint('NOAAalertCount', 2) # default 2 alerts enableExtraLocationWx = config['location'].getboolean('enableExtraLocationWx', False) # default False