Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix weather.py to work with new Yahoo API changes #1058

Merged
merged 1 commit into from
Apr 25, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions sopel/modules/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,16 @@ def weather(bot, trigger):
if not woeid:
return bot.reply("I don't know where that is.")

query = web.urlencode({'w': woeid, 'u': 'c'})
raw = web.get('http://weather.yahooapis.com/forecastrss?' + query,
query = 'q=select * from weather.forecast where woeid="%s" and u=\'c\'' % woeid
body = web.get('http://query.yahooapis.com/v1/public/yql?' + query,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still using deprecated web.get. move past that on another pull request later

dont_decode=True)
parsed = xmltodict.parse(raw).get('rss')
location = parsed.get('channel').get('title')

cover = get_cover(parsed)
temp = get_temp(parsed)
humidity = get_humidity(parsed)
wind = get_wind(parsed)
parsed = xmltodict.parse(body).get('query')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new API provides JSON so future pull request will move past XML

results = parsed.get('results')
location = results.get('channel').get('title')
cover = get_cover(results)
temp = get_temp(results)
humidity = get_humidity(results)
wind = get_wind(results)
bot.say(u'%s: %s, %s, %s, %s' % (location, cover, temp, humidity, wind))


Expand Down Expand Up @@ -178,6 +178,5 @@ def update_woeid(bot, trigger):
city = first_result.get('name')
state = first_result.get('admin1').get('#text') or ''
country = first_result.get('country').get('#text') or ''
uzip = first_result.get('postal').get('#text') or ''
bot.reply('I now have you at WOEID %s (%s%s, %s, %s %s)' %
(woeid, neighborhood, city, state, country, uzip))
bot.reply('I now have you at WOEID %s (%s%s, %s, %s)' %
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yahoo's new API doesn't always return a zip code

(woeid, neighborhood, city, state, country))