From 4545b8f4a4c72e2b2be50d407f08628aecc851c5 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Mon, 28 Apr 2025 23:10:52 -0700 Subject: [PATCH] Update locationdata.py --- modules/locationdata.py | 42 ++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/modules/locationdata.py b/modules/locationdata.py index 9da4bbb..477a35b 100644 --- a/modules/locationdata.py +++ b/modules/locationdata.py @@ -639,25 +639,29 @@ def get_volcano_usgs(lat=0, lon=0): return ERROR_FETCHING_DATA volcano_json = volcano_data.json() # extract alerts from main feed - for alert in volcano_json: - # check ignore list - if ignoreUSGSEnable: - for word in ignoreUSGSwords: - if word.lower() in alert['volcano_name_appended'].lower(): - logger.debug(f"System: Ignoring USGS Alert: {alert['volcano_name_appended']} containing {word}") - continue - # check if the alert lat long is within the range of bot latitudeValue and longitudeValue - if (alert['latitude'] >= latitudeValue - 10 and alert['latitude'] <= latitudeValue + 10) and (alert['longitude'] >= longitudeValue - 10 and alert['longitude'] <= longitudeValue + 10): - volcano_name = alert['volcano_name_appended'] - alert_level = alert['alert_level'] - color_code = alert['color_code'] - cap_severity = alert['cap_severity'] - synopsis = alert['synopsis'] - # format Alert - alerts += f"🌋🚨: {volcano_name}, {alert_level} {color_code}, {cap_severity}.\n{synopsis}\n" - else: - #logger.debug(f"System: USGS volcano alert not in range: {alert['volcano_name_appended']}") - continue + if volcano_json and isinstance(volcano_json, list): + for alert in volcano_json: + # check ignore list + if ignoreUSGSEnable: + for word in ignoreUSGSwords: + if word.lower() in alert['volcano_name_appended'].lower(): + logger.debug(f"System: Ignoring USGS Alert: {alert['volcano_name_appended']} containing {word}") + continue + # check if the alert lat long is within the range of bot latitudeValue and longitudeValue + if (alert['latitude'] >= latitudeValue - 10 and alert['latitude'] <= latitudeValue + 10) and (alert['longitude'] >= longitudeValue - 10 and alert['longitude'] <= longitudeValue + 10): + volcano_name = alert['volcano_name_appended'] + alert_level = alert['alert_level'] + color_code = alert['color_code'] + cap_severity = alert['cap_severity'] + synopsis = alert['synopsis'] + # format Alert + alerts += f"🌋🚨: {volcano_name}, {alert_level} {color_code}, {cap_severity}.\n{synopsis}\n" + else: + #logger.debug(f"System: USGS volcano alert not in range: {alert['volcano_name_appended']}") + continue + else: + logger.debug("Location:Error fetching volcano data from USGS") + return NO_ALERTS if alerts == "": return NO_ALERTS # trim off last newline