summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschneefux <schneefux+commit@schneefux.xyz>2014-04-09 17:43:08 +0100
committerschneefux <schneefux+commit@schneefux.xyz>2014-04-09 17:43:08 +0100
commitf419f389ea563bded70b88b86d3db54d93d5adca (patch)
tree333e68021707d843fb6859647e35b2ea385fec76
parent658f13304f51543188e5a2ca2a4850a1901d1dde (diff)
downloadjasper-client-f419f389ea563bded70b88b86d3db54d93d5adca.tar.gz
jasper-client-f419f389ea563bded70b88b86d3db54d93d5adca.zip
Add international weather
If not in US, uses nearest city/town instead. Wunderground handles this without any changes. Verifies that Wunderground returns a forecase.
-rw-r--r--client/populate.py24
1 files changed, 17 insertions, 7 deletions
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(