]> jfr.im git - erebus.git/blobdiff - modules/weather.py
userinfo - refactor
[erebus.git] / modules / weather.py
index 2249abacfba44bb576cd85e20d06ddccdfb39c9a..27f21eca64c9d98740276614bb3ad45f9de399f5 100644 (file)
@@ -32,12 +32,16 @@ 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
+               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
+               measuredat = rfc822.parsedate(current['observation_time_rfc822']) # parsedate_tz returns a 10-tuple which strftime DOESN'T ACCEPT
                measuredatTZ = current['local_tz_short']
                output = u"Weather in %(location)s: As of %(time)s %(tz)s, %(conditions)s, %(cel)s\u00B0C (%(far)s\u00B0F) (feels like %(flcel)s\u00B0C (%(flfar)s\u00B0F)). Wind %(wind)s. %(link)s" % {
                        'location': current['observation_location']['full'],
@@ -50,4 +54,4 @@ def weather(bot, user, chan, realtarget, *args):
                }
                bot.msg(chan, output)
        else:
-               bot.msg(chan, "I don't know where to look! Try SETINFO LOCATION <your location>")
+               bot.msg(chan, "I don't know where to look! Try %sSETINFO LOCATION <your location>" % (bot.parent.trigger))