Weather forecast from command line

Lysá hora from Smrček

In some cases it is usefull to get a forecast from a command line.
So I have this code in my ~/.bashrc file on my Ben NanoNote:

forecast(){
curl -s "http://api.wunderground.com/auto/wui/geo/ForecastXML/index.xml?query=${@:-}"|perl -ne '/([^<]+)/&&printf "%s: ",$1;/([^<]+)/&&print $1,"\n"'|sed "s/&/\ /g"|sed "s/deg;//g";
}

Then I can invoke forecast info with the command “forecast Prague” where the Prague is a name of the city.
The result can be like this:

January 10, 2012: Fog. High 4 C (39 F). Winds 21 kph West
January 11, 2012: Partly Cloudy. High 5 C (41 F). Winds 25 kph WNW
January 12, 2012: Clear. High 6 C (42 F). Winds 21 kph West
January 13, 2012: Scattered Clouds. High 7 C (44 F). Winds 28 kph SW
January 14, 2012: Chance of Rain. High 3 C (37 F). Winds 32 kph WNW
January 15, 2012: Clear. High 4 C (39 F). Winds 28 kph NW

Of course I use the same thing on my desktops. The code is based on this. It uses date from the Weather Underground site.

Advertisements
Weather forecast from command line

Leave a Reply

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

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s