diff --git a/config.template b/config.template index 496e2ca..2191268 100644 --- a/config.template +++ b/config.template @@ -163,6 +163,8 @@ enableExtraLocationWx = False eAlertBroadcastEnabled = False # comma separated list of FIPS codes to trigger local alert. find your FIPS codes at https://en.wikipedia.org/wiki/Federal_Information_Processing_Standard_state_code myFIPSList = 57,58,53 +# find your SAME https://www.weather.gov/nwr/counties comma separated list of SAME code to further refine local alert. +mySAMEList = 053029,053073 # Goverment Alert Broadcast Channels eAlertBroadcastCh = 2 # Enable Ignore, headline that includes following word list diff --git a/modules/locationdata.py b/modules/locationdata.py index 9da299f..d7a86af 100644 --- a/modules/locationdata.py +++ b/modules/locationdata.py @@ -528,6 +528,10 @@ def getIpawsAlert(lat=0, lon=0, shortAlerts = False): continue for info in linked_xml.getElementsByTagName("info"): + # only get en-US language alerts (alternative is es-US) + language_nodes = info.getElementsByTagName("language") + if not any(node.firstChild and node.firstChild.nodeValue.strip() == "en-US" for node in language_nodes): + continue # skip if not en-US # extract values from XML sameVal = "NONE" geocode_value = "NONE" @@ -545,32 +549,43 @@ def getIpawsAlert(lat=0, lon=0, shortAlerts = False): area_table = info.getElementsByTagName("area")[0] areaDesc = area_table.getElementsByTagName("areaDesc")[0].childNodes[0].nodeValue + geocode_table = area_table.getElementsByTagName("geocode")[0] + geocode_type = geocode_table.getElementsByTagName("valueName")[0].childNodes[0].nodeValue + geocode_value = geocode_table.getElementsByTagName("value")[0].childNodes[0].nodeValue + if geocode_type == "SAME": + sameVal = geocode_value except Exception as e: logger.debug(f"System: iPAWS Error extracting alert data: {link}") #print(f"DEBUG: {info.toprettyxml()}") continue - # ignore the FEMA test alerts - if ignoreFEMAenable: - ignore_alert = False - for word in ignoreFEMAwords: - if word.lower() in headline.lower(): - logger.debug(f"System: Ignoring FEMA Alert: {headline} containing {word} at {areaDesc}") - ignore_alert = True - break - + # check if the alert is for the SAME location, if wanted keep alert + if (sameVal in mySAMEList) or (geocode_value in mySAMEList): + # ignore the FEMA test alerts + if ignoreFEMAenable: + ignore_alert = False + for word in ignoreFEMAwords: + if word.lower() in headline.lower(): + logger.debug(f"System: Filtering FEMA Alert by WORD: {headline} containing {word} at {areaDesc}") + ignore_alert = True + break if ignore_alert: continue - # add to alerts list - alerts.append({ - 'alertType': alertType, - 'alertCode': alertCode, - 'headline': headline, - 'areaDesc': areaDesc, - 'description': description - }) + # add to alert list + alerts.append({ + 'alertType': alertType, + 'alertCode': alertCode, + 'headline': headline, + 'areaDesc': areaDesc, + 'geocode_type': geocode_type, + 'geocode_value': geocode_value, + 'description': description + }) + else: + logger.debug(f"System: iPAWS Alert not in SAME List: {sameVal} or {geocode_value} for {headline} at {areaDesc}") + continue # return the numWxAlerts of alerts if len(alerts) > 0: @@ -684,5 +699,3 @@ def get_volcano_usgs(lat=0, lon=0): # return the alerts alerts = abbreviate_noaa(alerts) return alerts - - diff --git a/modules/settings.py b/modules/settings.py index 9e97e06..ea23be9 100644 --- a/modules/settings.py +++ b/modules/settings.py @@ -264,6 +264,7 @@ try: numWxAlerts = config['location'].getint('NOAAalertCount', 2) # default 2 alerts enableExtraLocationWx = config['location'].getboolean('enableExtraLocationWx', False) # default False myStateFIPSList = config['location'].get('myFIPSList', '').split(',') # default empty + mySAMEList = config['location'].get('mySAMEList', '').split(',') # default empty ignoreFEMAenable = config['location'].getboolean('ignoreFEMAenable', True) # default True ignoreFEMAwords = config['location'].get('ignoreFEMAwords', 'test,exercise').split(',') # default test,exercise wxAlertBroadcastChannel = config['location'].get('wxAlertBroadcastCh', '2').split(',') # default Channel 2