Skip to content

Commit

Permalink
Initial commit for weather plugin created by uberj
Browse files Browse the repository at this point in the history
  • Loading branch information
dean committed Aug 12, 2014
0 parents commit c7f8c4e
Show file tree
Hide file tree
Showing 8 changed files with 450 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/bin/
/dist/
/include/
/lib/
354 changes: 354 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
recursive-include hamper-remindme *.py
include LICENSE
include README.md
include requirements.txt
include setup.py
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Reminder plugin for the IRC bot hamper.

INSTALL
=======

```shell
pip install git+https://github.com/johnsdea/hamper-remindme.git
```

1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pyquery==1.2.4
15 changes: 15 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from setuptools import setup

with open('requirements.txt') as f:
requirements = [l.strip() for l in f]

setup(
name='weather',
version='0.1',
packages=['weather'],
author='',
author_email='',
url='https://github.com/hamperbot/weather',
install_requires=requirements,
package_data={'weather': ['requirements.txt', 'README.md', 'LICENSE']}
)
1 change: 1 addition & 0 deletions weather/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

61 changes: 61 additions & 0 deletions weather/weather.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from pyquery import PyQuery as pq
import requests

from hamper.interfaces import ChatCommandPlugin, Command


class NoData(Exception):
pass


class Weather(ChatCommandPlugin):
"""What's the weather?"""
name = 'weather'
priority = 2
short_desc = 'weather <location> - look the weather for a location'
long_desc = 'Try !weather <zip-code> or !weather <city> <state>'

class Weather(Command):
name = 'weather'
regex = '^weather\s*(.*)'
api_url = 'http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query={0}' # noqa

def command(self, bot, comm, groups):
query = groups[0].strip()
if not query:
bot.reply(comm, self.plugin.long_desc)
return False

resp = requests.get(self.api_url.format(query))
dom = pq(resp.content)
if not resp.status_code == 200:
bot.reply(
comm,
"Error while looking up weather: saw status code %s" %
resp.status_code
)
return False

try:
location = dom('display_location full')[0].text
if location == ', ':
raise NoData()
cur_weather = dom('weather')[0].text
temp = dom('temperature_string')[0].text
relative_humidity = dom('relative_humidity')[0].text
station = dom('station_id')[0].text
except (IndexError, NoData):
bot.reply(comm, "Couldn't find weather for {0}".format(query))
return False

weather_resp = (
"The reported weather for {0} ({1}) is {2} -- "
"{3} with a relative humidity of {4}"
).format(location, station, cur_weather, temp, relative_humidity)

bot.reply(comm, weather_resp)

return False


weather = Weather()

0 comments on commit c7f8c4e

Please sign in to comment.