]> jfr.im git - erebus.git/commitdiff
weather - handle wundergrounds terrible API response formatting
authorzonidjan <redacted>
Tue, 7 Nov 2017 00:36:09 +0000 (18:36 -0600)
committerzonidjan <redacted>
Tue, 7 Nov 2017 00:36:09 +0000 (18:36 -0600)
modules/weather.py

index 2249abacfba44bb576cd85e20d06ddccdfb39c9a..5157a7dcd232535953bf1037c4194672283c28c0 100644 (file)
@@ -32,9 +32,14 @@ def weather(bot, user, chan, realtarget, *args):
 
        if place is not None:
                weather = json.load(urllib.urlopen('http://api.wunderground.com/api/8670e6d2e69ff3c7/conditions/q/%s.json' % (place)))
-               if 'error' in weather:
-                       bot.msg(chan, "Error from Wunderground: %s" % (weather['error']['description']))
-                       return
+               print `weather`
+               if 'response' in weather:
+                       if 'error' in weather['response']:
+                               bot.msg(chan, "Error from Wunderground: %s" % (weather['response']['error']['description']))
+                               return
+                       if 'results' in weather['response']:
+                               bot.msg(chan, "That search term is ambiguous. Please be more specific.")
+                               return
 
                current = weather['current_observation']
                measuredat = rfc822.parsedate_tz(current['observation_time_rfc822'])[:-1] # parsedate_tz returns a 10-tuple which strftime DOESN'T ACCEPT