]>
Commit | Line | Data |
---|---|---|
b069ba10 JR |
1 | from classes import * |
2 | from util import * | |
3 | ||
4 | import httplib, json | |
5 | ||
6 | apikey = '6117a56225f311c3' | |
7 | ||
8 | name = 'weather underground' | |
9 | def 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) | |
13 | def deinit(cache, reloading=False): | |
14 | cache.currmod = __name__ | |
15 | cache.unhookcmd('WEATHER') | |
16 | cache.unhookcmd('W') | |
17 | ||
18 | def 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 | ||
33 | def helpweather(): | |
34 | return ['WEATHER <location>', 'Gets weather data from Weather Underground'] | |
35 | def helpw(): | |
36 | return ['W <location>', 'Alias for WEATHER.'] |