Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Use Wunderground for weather reports.

  • Loading branch information...
commit da3b9fd6b1c900fa82741ae9727bd468062b1c10 1 parent 6cec23e
Josh Kearney jk0 authored
2  README
@@ -12,7 +12,7 @@ Plugin Requirements
12 12
13 13 - launchpadlib
14 14 - pycleverbot
15   - - pywapi
  15 + - pywunderground
16 16
17 17
18 18 Test Requirements
27 pyhole/plugins/weather.py
@@ -14,7 +14,7 @@
14 14
15 15 """Pyhole Weather Plugin"""
16 16
17   -import pywapi
  17 +import pywunderground
18 18
19 19 from pyhole import plugin
20 20 from pyhole import utils
@@ -27,6 +27,9 @@ class Weather(plugin.Plugin):
27 27 @utils.spawn
28 28 def weather(self, params=None, **kwargs):
29 29 """Display current weather report (ex: .w [set] [<location>])"""
  30 + wunderground = utils.get_config("Wunderground")
  31 + api_key = wunderground.get("key")
  32 +
30 33 if params:
31 34 location = params
32 35 if location.startswith("set "):
@@ -40,21 +43,23 @@ def weather(self, params=None, **kwargs):
40 43 return
41 44
42 45 try:
43   - w = pywapi.get_weather_from_google(location)
  46 + w = pywunderground.request(api_key, ["conditions"], location)
44 47 except Exception:
45 48 self.irc.reply("Unable to fetch weather data")
46 49 return
47 50
48   - if w["current_conditions"]:
49   - city = w["forecast_information"]["city"]
50   - temp_f = w["current_conditions"]["temp_f"]
51   - temp_c = w["current_conditions"]["temp_c"]
52   - humidity = w["current_conditions"]["humidity"]
53   - wind = w["current_conditions"]["wind_condition"]
54   - condition = w["current_conditions"]["condition"]
  51 + if w.get("current_observation"):
  52 + city = w["current_observation"]["display_location"]["full"]
  53 + zip_code = w["current_observation"]["display_location"]["zip"]
  54 + temp = w["current_observation"]["temperature_string"]
  55 + humidity = w["current_observation"]["relative_humidity"]
  56 + wind = w["current_observation"]["wind_string"]
  57 + condition = w["current_observation"]["weather"]
  58 +
  59 + zip_code = "" if zip_code == "00000" else " %s" % zip_code
  60 + result = "%s%s: %s Humidity: %s Wind: %s %s" % (city,
  61 + zip_code, temp, humidity, wind, condition)
55 62
56   - result = "%s: %sF/%sC %s %s %s" % (city, temp_f, temp_c,
57   - humidity, wind, condition)
58 63 self.irc.reply(result)
59 64 else:
60 65 self.irc.reply("Location not found: '%s'" % location)
5 pyhole/utils.py
@@ -153,9 +153,12 @@ def generate_config():
153 153 reconnect_delay: 60
154 154 rejoin_delay: 5
155 155 debug: False
156   -plugins: admin, dice, entertainment, news, search, urls, weather
  156 +plugins: admin, dice, entertainment, news, search, urls
157 157 networks: FreeNode, EFnet
158 158
  159 +[Wunderground]
  160 +key: abcd1234
  161 +
159 162 [Redmine]
160 163 domain: redmine.example.com
161 164 key: abcd1234
2  pyhole/version.py
@@ -20,7 +20,7 @@
20 20 import sys
21 21
22 22
23   -__VERSION__ = "0.6.2"
  23 +__VERSION__ = "0.6.3"
24 24
25 25
26 26 def current_git_hash():
2  tools/pip-requires
@@ -2,4 +2,4 @@ BeautifulSoup==3.2.0
2 2 Eventlet
3 3 launchpadlib
4 4 nose
5   -pywapi
  5 +pywunderground

0 comments on commit da3b9fd

Please sign in to comment.
Something went wrong with that request. Please try again.