Skip to content


Command line weather forecast

For those who like to live in command line and python script to tell you what the weather is like (although if you live on the CL you probably don’t go outside much so it’s pretty irrelevant).

The weather forecast is from Yahoo weather, after entering your locale get the code from the url, for example http://weather.yahoo.com/forecast/UKXX0123.html is Glasgow. The part we are interested in is the code “UKXX0123″.

Save the script as “weather”, make it executable and put in executable directory like /usr/local/bin

Now open a new terminal window and you should get this:

test@testing:~$ weather

Current Conditions:
Partly Cloudy, 13 C
Forecast:
Mon - Partly Cloudy. High: 14 Low: 7
Tue - Partly Cloudy. High: 16 Low: 8

Now the code.

#!/usr/bin/env python
import feedparser,re
feed="http://weather.yahooapis.com/forecastrss?p=YOUR-CODE-HERE&u=c"
data=feedparser.parse(feed)
pattern='<.+?>'
summary=data.entries[0].summary
forecast=re.sub(pattern,'',summary)
forecast=re.split('\n',forecast)
for line in forecast[0:-2]:
    print line

Posted in geek, python.

Tagged with , , , .


4 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

Continuing the Discussion

  1. CLIFFORD linked to this post on July 6, 2010


    Pillspot.org. Canadian Health&Care.Best quality drugs.Special Internet Prices.No prescription online pharmacy. Low price pills. Buy drugs online

    Buy:Viagra.Propecia.Super Active ED Pack.Levitra.Viagra Super Force.Soma.Viagra Soft Tabs.Maxaman.Cialis Super Active+.Cialis.Cialis Soft Tabs.Viagra Super Active+.Cialis Professional.Tramadol.VPXL.Viagra Professional.Zithromax….

  2. PAUL linked to this post on July 15, 2010


    PillSpot.org. Canadian Health&Care.No prescription online pharmacy.Special Internet Prices.Best quality drugs. No prescription drugs. Order pills online

    Buy:Retin-A.Accutane.Prevacid.Prednisolone.Zyban.Petcam (Metacam) Oral Suspension.Arimidex.100% Pure Okinawan Coral Calcium.Human Growth Hormone.Actos.Valtrex.Mega Hoodia.Zovirax.Nexium.Lumigan.Synthroid….

  3. volt linked to this post on August 30, 2010

    Battery http://tarctic71xs.APTAUTOPARTS.INFO/tag/Volt+Rechargeable+Battery+For+Spot+Light+light+volt/ : Battery…

    Spot…

  4. ERNEST linked to this post on December 6, 2010

    .

    Buy:Viagra Super Active+.Viagra Soft Tabs.Viagra Professional.Maxaman.Tramadol.Cialis Super Active+.Super Active ED Pack.Cialis.VPXL.Soma.Cialis Professional.Levitra.Viagra Super Force.Cialis Soft Tabs.Viagra.Propecia.Zithromax….

You must be logged in to post a comment.