From ccf0ef5e337627c13e718fa93ae4ee76a74c8e78 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Wed, 10 Jul 2024 16:19:52 -0700 Subject: [PATCH] Update locationdata.py --- modules/locationdata.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/modules/locationdata.py b/modules/locationdata.py index 8a892bd..8fe79d1 100644 --- a/modules/locationdata.py +++ b/modules/locationdata.py @@ -12,7 +12,7 @@ URL_TIMEOUT = 10 # wait time for URL requests DAYS_OF_WEATHER = 4 # weather forecast days, the first two rows are today and tonight # error messages ALERT_COUNT = 2 # number of weather alerts to display -NO_DATA_NOGPS = "no location data: does your device have GPS?" +NO_DATA_NOGPS = "No location data: does your device have GPS?" ERROR_FETCHING_DATA = "error fetching data" trap_list_location = ("whereami", "tide", "moon", "wx", "wxc", "wxa", "wxalert") @@ -122,13 +122,21 @@ def get_weather(lat=0, lon=0, unit=0): # get any alerts and return the count alerts = getWeatherAlerts(lat, lon) - alert = alerts[0] - if alert == "No weather alerts found": + + if alerts == "No weather alerts found" or alerts == ERROR_FETCHING_DATA or alerts == NO_DATA_NOGPS: alert = "" alert_num = 0 else: + alert = alerts[0] alert_num = alerts[1] + if alert == "No weather alerts found" or alert == "": + alert = "" + alert_num = 0 + print("No Alerts") + else: + alert_num = int(alerts[1]) + if alert_num > 0: # add the alert count warning to the weather weather = str(alert_num) + " local alerts!\n" + weather + "\n" + alert