diff --git a/locationdata.py b/locationdata.py index 06d58b0..3b521f2 100644 --- a/locationdata.py +++ b/locationdata.py @@ -72,19 +72,25 @@ def get_weather(lat=0, lon=0): if(weather_data.ok): soup = bs.BeautifulSoup(weather_data.text, 'html.parser') table = soup.find('div', id="detailed-forecast-body") - #get rows - rows = table.find_all('div', class_="row") + + if table is None: + return "no weather data found on NOAA for your location" + else: + #get rows + rows = table.find_all('div', class_="row") #extract data from rows for row in rows: #shrink the text - line = row.text.replace("Monday", "Mon") \ - .replace("Tuesday", "Tue") \ - .replace("Wednesday", "Wed") \ - .replace("Thursday", "Thu") \ - .replace("Friday", "Fri") \ - .replace("Saturday", "Sat") \ - .replace("Sunday", "Sun") \ + line = row.text.replace("Monday", "Mon ") \ + .replace("Tuesday", "Tue ") \ + .replace("Wednesday", "Wed ") \ + .replace("Thursday", "Thu ") \ + .replace("Friday", "Fri ") \ + .replace("Saturday", "Sat ") \ + .replace("Today", "Today ") \ + .replace("Tonight", "Tonight ") \ + .replace("Tomorrow", "Tomorrow ") \ .replace("northwest", "NW") \ .replace("northeast", "NE") \ .replace("southwest", "SW") \