Commits

Jason R. Coombs committed 010fb4a

It seems Google has started to block the Python client for requests for weather in Palo Alto... so lie about the user agent.

Comments (0)

Files changed (2)

 	url = "http://www.google.com/ig/api?" + urllib.urlencode(dict(
 		weather= place.encode('utf-8')))
 	parser = ElementTree.XMLParser()
-	wdata = ElementTree.parse(urllib.urlopen(url), parser=parser)
+	wdata = ElementTree.parse(util.open_url(url), parser=parser)
 	city = wdata.find('weather/forecast_information/city').get('data')
 	tempf = wdata.find('weather/current_conditions/temp_f').get('data')
 	tempc = wdata.find('weather/current_conditions/temp_c').get('data')
 	c = filter(None, c)
 	return c
 
-def get_html(url):
+def open_url(url):
 	headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) '
 		'Gecko/20100101 Firefox/12.0'}
 	req = urllib2.Request(url, headers=headers)
-	return urllib2.urlopen(req).read()
+	return urllib2.urlopen(req)
+
+def get_html(url):
+	return open_url(url).read()
 
 def_exp1 = re.compile(r"<div><span class=f>.*?</span>(.+?)</div>", re.MULTILINE)
 def_exp2 = re.compile(r"Definition for.*<div class=s><div>(.+?)<", re.MULTILINE)