]> jfr.im git - z_archive/Ophion.git/blame - modules/autoload/weather.py
Initialize repo
[z_archive/Ophion.git] / modules / autoload / weather.py
CommitLineData
b069ba10
JR
1from classes import *
2from util import *
3
4import httplib, json
5
6apikey = '6117a56225f311c3'
7
8name = 'weather underground'
9def init(cache):
10 cache.currmod = __name__
11 cache.hookcmd('WEATHER', 0, weather, 1, helpweather, reqchan=False)
12 cache.hookcmd('W', 0, weather, 1, helpw, reqchan=False)
13def deinit(cache, reloading=False):
14 cache.currmod = __name__
15 cache.unhookcmd('WEATHER')
16 cache.unhookcmd('W')
17
18def weather(nick, target, params, bot, cache):
19 location = params.strip().replace(' ', '_')
20 conn = httplib.HTTPConnection("api.wunderground.com")
21 conn.request("GET", "/api/%s/conditions/q/%s.json" % (apikey, location))
22 res = conn.getresponse()
23 if res.status == 200:
24 data = res.read()
25 wz = json.loads(data)
26 if 'current_observation' in wz:
27 wz = wz['current_observation']
28 buf = "Weather for %s, %s: %s - Feels like: %s - Conditions: %s - Humidity: %s. %s" % (wz['display_location']['full'], wz['display_location']['country_iso3166'], wz['temperature_string'], wz['feelslike_string'], wz['weather'], wz['relative_humidity'], wz['observation_time'])
29 bot.msg(target, buf)
30 return
31 bot.msg(target, "Error retrieving weather.")
32
33def helpweather():
34 return ['WEATHER <location>', 'Gets weather data from Weather Underground']
35def helpw():
36 return ['W <location>', 'Alias for WEATHER.']