Get weather forecast

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.
For example, I searched Tokyo then I got WOEID 1118370.
So, let’s write a code.

# 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"%(,
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$ 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.


Published by iwatobipen

I'm medicinal chemist in mid size of pharmaceutical company. I love chemoinfo, cording, organic synthesis, my family.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: