I found nice tool for python .
It’s name “weatherpy”.
A python wrapper for the Yahoo weather API.
It’s easy to install.
lion$ pip install weatherpy
Give weatherpy a user agent and a WOEID and weatherpy will make accessing elements of the RSS feed simple.
WOEID (Where On Earth Identifiers) can be found here.
http://woeid.rosselliot.co.nz/
For example, I searched Tokyo then I got WOEID 1118370.
So, let’s write a code.
#!/usr/env/python # weatherpy import weatherpy import sys query = long(sys.argv[1]) res = weatherpy.Response(' test user ', query) units = res.units wind = res.wind conditions = res.condition astro = res.astronomy location = res.location print res.title print "%s, %s"%(res.location.country, res.location.city) print conditions.date print conditions.text print "Temp: %s, %s"%(conditions.temperature, units.temperature) print "Wind: %s, %s, %s, %s"%(wind.speed, units.speed, wind.direction, wind.cardinal_direction()) print "Sunrise: ", astro.sunrise print "Sunset: ", astro.sunset
Let’s run the script
lion$ get_weather.py 1118370
Then, I got following data.
Yahoo! Weather - Tokyo, JP Japan, Tokyo 2013-09-05 22:59:00 Partly Cloudy Temp: 27, C Wind: 19.31, km/h, 220, N Sunrise: 5:14 am Sunset: 6:02 pm
It’s easy and cool.