From 5871b0202d3a346af390963e27baaea24f9d2d8a Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Thu, 27 Jun 2024 12:17:16 -0700 Subject: [PATCH] Update locationdata.py --- modules/locationdata.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/locationdata.py b/modules/locationdata.py index 44a4ff7..2165fb2 100644 --- a/modules/locationdata.py +++ b/modules/locationdata.py @@ -9,7 +9,7 @@ import bs4 as bs # pip install beautifulsoup4 URL_TIMEOUT = 10 # wait time for URL requests DAYS_OF_WEATHER = 4 # weather forecast days, the first two rows are today and tonight -# unified error messages to be able to test them from tests +# error messages NO_DATA_NOGPS = "no location data: does your device have GPS?" ERROR_FETCHING_DATA = "error fetching data" @@ -134,9 +134,14 @@ def get_wx_alerts(lat=0, lon=0): return ERROR_FETCHING_DATA except (requests.exceptions.RequestException): return ERROR_FETCHING_DATA - + soup = bs.BeautifulSoup(alert_data.text, 'html.parser') - alerts = soup.text + + alert_count = soup.find('span', class_="details-count") + if alert_count is None: + return "no weather alerts found" + else: + alerts += alert_count.text + "\n" return alerts