]> jfr.im git - erebus.git/blobdiff - modules/weatherstack_weather.py
fix exception when parting a channel
[erebus.git] / modules / weatherstack_weather.py
index a79ff78d115fc1fa5a2822e5933f4c0efc3e634f..d6140d131367dfd3cdfb29d72c550f950268a77b 100644 (file)
@@ -1,6 +1,6 @@
 # Erebus IRC bot - Author: Erebus Team
 # vim: fileencoding=utf-8
-# weather module
+# weather module (from WeatherStack, boo)
 # This file is released into the public domain; see http://unlicense.org/
 
 # module info
@@ -53,7 +53,10 @@ def _weather(place):
                return "Weather is not enabled - please set the API key in the config file"
 
        if place is not None:
-               weather = json.load(urlopen(('http://api.weatherstack.com/current?access_key=%s&query=%s' % (lib.parent.cfg.get('weatherstack_weather', 'key'), quote_plus(place))).encode('utf8')))
+               url = 'http://api.weatherstack.com/current?access_key=%s&query=%s' % (lib.parent.cfg.get('weatherstack_weather', 'key'), quote_plus(place))
+               if sys.version_info.major < 3:
+                       url = url.encode('utf8')
+               weather = json.load(urlopen(url))
                if lib.parent.cfg.getboolean('debug', 'weather'):
                        lib.parent.log('*', "?", repr(weather))
                if 'error' in weather: