diff --git a/config.template b/config.template index d503094..7cefbfe 100644 --- a/config.template +++ b/config.template @@ -134,24 +134,34 @@ 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 +myRegionalKeysDE = 110000000000,120510000000 + # Satalite Pass Prediction # Register for free API https://www.n2yo.com/login/ n2yoAPIKey = diff --git a/mesh_bot.py b/mesh_bot.py index 32373ac..e4ab063 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..9589d48 100644 --- a/modules/globalalert.py +++ b/modules/globalalert.py @@ -27,7 +27,23 @@ 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 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 DE alerts: " + str(e)) + return NO_ALERTS def get_wxUKgov(): # get UK weather warnings @@ -57,4 +73,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 351ecda..0e7af76 100644 --- a/modules/settings.py +++ b/modules/settings.py @@ -241,8 +241,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 + 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 diff --git a/modules/system.py b/modules/system.py index f9aed18..b408af4 100644 --- a/modules/system.py +++ b/modules/system.py @@ -656,6 +656,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 @@ -671,6 +672,8 @@ def handleAlertBroadcast(deviceID=1): alertWx = alertBrodcastNOAA() if emergencyAlertBrodcastEnabled: + if enableDEalerts: + alertDe = get_nina_alerts() if enableGBalerts: alertUk = get_govUK_alerts() else: @@ -685,6 +688,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: @@ -701,6 +705,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)