Skip to content

Commit

Permalink
Merge pull request #927 from maxpowa/patch-2
Browse files Browse the repository at this point in the history
Resolve #926
  • Loading branch information
embolalia committed Nov 15, 2015
2 parents ebfd6bd + 9b0e4c7 commit 5c94984
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
1 change: 0 additions & 1 deletion contrib/rpm/willie.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ BuildRequires: dos2unix
BuildRequires: systemd

Requires: pytz
Requires: python-feedparser
Requires: python-enchant
Requires: pyOpenSSL
Requires: python-praw
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
feedparser
xmltodict
pytz
praw
Expand Down
26 changes: 13 additions & 13 deletions sopel/modules/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from sopel import web
from sopel.module import commands, example, NOLIMIT

import feedparser
import xmltodict


Expand All @@ -36,19 +35,19 @@ def woeid_search(query):

def get_cover(parsed):
try:
condition = parsed.entries[0]['yweather_condition']
condition = parsed['channel']['item']['yweather:condition']
except KeyError:
return 'unknown'
text = condition['text']
text = condition['@text']
# code = int(condition['code'])
# TODO parse code to get those little icon thingies.
return text


def get_temp(parsed):
try:
condition = parsed.entries[0]['yweather_condition']
temp = int(condition['temp'])
condition = parsed['channel']['item']['yweather:condition']
temp = int(condition['@temp'])
except (KeyError, ValueError):
return 'unknown'
f = round((temp * 1.8) + 32, 2)
Expand All @@ -57,19 +56,19 @@ def get_temp(parsed):

def get_humidity(parsed):
try:
humidity = parsed['feed']['yweather_atmosphere']['humidity']
humidity = parsed['channel']['yweather:atmosphere']['@humidity']
except (KeyError, ValueError):
return 'unknown'
return "Humidity: %s%%" % humidity


def get_wind(parsed):
try:
wind_data = parsed['feed']['yweather_wind']
kph = float(wind_data['speed'])
wind_data = parsed['channel']['yweather:wind']
kph = float(wind_data['@speed'])
m_s = float(round(kph / 3.6, 1))
speed = int(round(kph / 1.852, 0))
degrees = int(wind_data['direction'])
degrees = int(wind_data['@direction'])
except (KeyError, ValueError):
return 'unknown'

Expand Down Expand Up @@ -144,9 +143,10 @@ def weather(bot, trigger):
return bot.reply("I don't know where that is.")

query = web.urlencode({'w': woeid, 'u': 'c'})
url = 'http://weather.yahooapis.com/forecastrss?' + query
parsed = feedparser.parse(url)
location = parsed['feed']['title']
raw = web.get('http://weather.yahooapis.com/forecastrss?' + query,
dont_decode=True)
parsed = xmltodict.parse(raw).get('rss')
location = parsed.get('channel').get('title')

cover = get_cover(parsed)
temp = get_temp(parsed)
Expand All @@ -171,7 +171,7 @@ def update_woeid(bot, trigger):

bot.db.set_nick_value(trigger.nick, 'woeid', woeid)

neighborhood = first_result.get('neighborhood').text or ''
neighborhood = first_result.get('neighborhood') or ''
if neighborhood:
neighborhood += ','
city = first_result.get('city') or ''
Expand Down

0 comments on commit 5c94984

Please sign in to comment.