Merge pull request #1123 from ZyX-I/weather-diagnostics

Include raw_response in error message in weather segment
This commit is contained in:
Nikolai Aleksandrovich Pavlov 2014-10-18 21:38:06 +04:00
commit f0d2f2884e
1 changed files with 9 additions and 4 deletions

View File

@ -139,11 +139,16 @@ class WeatherSegment(KwThreadedSegment):
raw_response = urllib_read(url)
if not raw_response:
self.error('Failed to get response')
return
return None
response = json.loads(raw_response)
condition = response['query']['results']['weather']['rss']['channel']['item']['condition']
condition_code = int(condition['code'])
temp = float(condition['temp'])
try:
condition = response['query']['results']['weather']['rss']['channel']['item']['condition']
condition_code = int(condition['code'])
temp = float(condition['temp'])
except (KeyError, ValueError):
self.exception('Yahoo returned malformed or unexpected response: {0}', repr(raw_response))
return None
try:
icon_names = weather_conditions_codes[condition_code]