Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/env python
""" Script that prints out tomorrow's weather forecast, using the Yahoo Weather API.
You'll need to get your location's WOEID, which you can get from entering your
location in the form on - currently where it says
'Enter city of zip code'.
The WOEID numerical id will be in the URL of the page you get redirected to
after submitting the form e.g. in the URL the
WOEID is 30079. """
import json
import urllib2
import os
def get_weather(woeid):
url = '' % (woeid)
return json.load(urllib2.urlopen(url))
if __name__ == '__main__':
newcastle = 30079
weather = get_weather(newcastle)
location = weather['location']
tomorrow = weather['forecast'][1]
print 'location: %s, %s' % (location['city'], location['state_abbreviation'])
print 'forecast for tomorrow: %s' % tomorrow['condition']
print 'high: %d' % tomorrow['high_temperature']
print 'low: %s' % tomorrow['low_temperature']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment