-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit for weather plugin created by uberj
- Loading branch information
0 parents
commit c7f8c4e
Showing
8 changed files
with
450 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/bin/ | ||
/dist/ | ||
/include/ | ||
/lib/ |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pyquery==1.2.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |