diff options
| author | schneefux <schneefux+commit@schneefux.xyz> | 2014-04-09 23:09:23 -0400 |
|---|---|---|
| committer | schneefux <schneefux+commit@schneefux.xyz> | 2014-04-09 23:09:23 -0400 |
| commit | 16e7c8dddb2b0449143241f0212c18b98df733a6 (patch) | |
| tree | c0fc8723e57d8ac1894d86900fee258557650f92 /client | |
| parent | 658f13304f51543188e5a2ca2a4850a1901d1dde (diff) | |
| parent | 2b129def696ac5ef6cc28f6c8d7b3dea86442337 (diff) | |
| download | jasper-client-16e7c8dddb2b0449143241f0212c18b98df733a6.tar.gz jasper-client-16e7c8dddb2b0449143241f0212c18b98df733a6.zip | |
Merge pull request #9 from alexbate/master
International weather
Diffstat (limited to 'client')
| -rw-r--r-- | client/modules/Weather.py | 10 | ||||
| -rw-r--r-- | client/populate.py | 24 |
2 files changed, 25 insertions, 9 deletions
diff --git a/client/modules/Weather.py b/client/modules/Weather.py index 85a8f1d..7bb86ec 100644 --- a/client/modules/Weather.py +++ b/client/modules/Weather.py @@ -76,12 +76,18 @@ def handle(text, mic, profile): for entry in forecast: try: date_desc = entry['title'].split()[0].strip().lower() + if date_desc == 'forecast': #For global forecasts + date_desc = entry['title'].split()[2].strip().lower() + weather_desc = entry['summary'] - weather_desc = entry['summary'].split('-')[1] + elif date_desc == 'current': #For first item of global forecasts + continue + else: + weather_desc = entry['summary'].split('-')[1] #US forecasts if weekday == date_desc: output = date_keyword + \ - ", the weather will be" + weather_desc + "." + ", the weather will be " + weather_desc + "." break except: continue diff --git a/client/populate.py b/client/populate.py index 7253f06..0887648 100644 --- a/client/populate.py +++ b/client/populate.py @@ -2,6 +2,7 @@ import re from getpass import getpass import yaml from pytz import timezone +import feedparser def run(): @@ -48,14 +49,23 @@ def run(): profile['carrier'] = carrier # location + def verifyLocation(place): + feed = feedparser.parse('http://rss.wunderground.com/auto/rss_full/' + place) + numEntries = len(feed['entries']) + if numEntries==0: + return False + else: + print("Location saved as " + feed['feed']['description'][33:]) + return True + print( - "Location should be a 5-digit US zipcode (e.g., 08544). For weather requests.") - zipcode = clean_number(raw_input("Zipcode: ")) - while zipcode and len(zipcode) != 5: - print("Invalid zipcode. Must be 5 digits.") - zipcode = clean_number(raw_input("Zipcode: ")) - if zipcode: - profile['location'] = zipcode + "Location should be a 5-digit US zipcode (e.g., 08544). If you are outside the US, insert the name of your nearest big town/city. For weather requests.") + location = raw_input("Location: ") + while location and (verifyLocation(location)==False): + print("Weather not found. Please try another location.") + location = raw_input("Location: ") + if location: + profile['location'] = location # timezone print( |
