weather: check weather conditions and forecasts on the command line
October 4th, 2007 edited by TinchoArticle submitted by Dann Frazier. We are running out of articles ! Please help DPOTD and submit good articles about software you like !
weather, provided by the weather-util package, is a simple command line tool that lets you check current conditions and forecasts. It uses METAR data that it fetches from the the National Oceanic and Atmospheric Administration and forecasts from the National Weather Service. The documentation says it’s limited to providing information for the United States, but in fact, METAR data is available for stations all around the world. The forecast won’t be available, though.
Many locations are already pre-configured in the package’s /etc/weatherrc
. If your location is already defined, you only need to look up the alias to begin using it. For example, /etc/weatherrc
provides the following entry for Albuquerque, New Mexico:
[ABQ] City = Albuquerque ID = KABQ St = NM
The alias for Albuquerque is ‘ABQ’. Therefore, weather ABQ will show you the current conditions for Albuquerque:
$ weather ABQ Current conditions at Albuquerque International Airport (KABQ) Last updated Sep 26, 2007 - 04:56 PM EDT / 2007.09.26 2056 UTC Wind: from the ESE (120 degrees) at 3 MPH (3 KT) Sky conditions: mostly clear Temperature: 77.0 F (25.0 C) Relative Humidity: 15%
weather -f ABQ will include a local forecast:
$ weather -f ABQ Current conditions at Albuquerque International Airport (KABQ) Last updated Sep 26, 2007 - 04:56 PM EDT / 2007.09.26 2056 UTC Wind: from the ESE (120 degrees) at 3 MPH (3 KT) Sky conditions: mostly clear Temperature: 77.0 F (25.0 C) Relative Humidity: 15% City Forecast for Albuquerque, NM Issued Wednesday afternoon - Sep 26, 2007 Wednesday night... Low 52, 0% chance of precipitation. Thursday... Sunny, high 81, 0% chance of precipitation. Thursday night... Low 54, 5% chance of precipitation. Friday... Partly cloudy, high 80. Friday night... Low 56.
You can add new locations to this file directly, or to per-user ~/.weatherrc
files. You can also define a default location by adding a stanza with an alias named “default”. For example, here’s the contents of my ~/.weatherrc
file:
[default] City = denver Forecast = True ID = KFNL St = CO
City
and St
(state) are used for obtaining forecasts, while ID
is used for retrieving current conditions. I use this configuration to tell weather to retrieve forecasts from Denver, CO but to use a station that is closer to me for obtaining current conditions. Note that if you do not specify a location and have no alias named ‘default’, weather will fall back to a hard-coded default of Raleigh, NC.
Knowing what information weather uses to obtain the data you request is important when defining your own configurations. For example, say I want to know the current conditions for Lubbock, TX and I run the following command:
$ weather -o --city=Lubbock --st=TX Current conditions at Fort Collins-Loveland Municipal Airport (KFNL) Last updated Sep 26, 2007 - 05:55 PM EDT / 2007.09.26 2155 UTC Wind: from the ENE (070 degrees) at 5 MPH (4 KT) Sky conditions: clear Temperature: 71 F (22 C) Relative Humidity: 23%
(The -o
tells weather to omit the forecast). Notice that weather gave me the current conditions for my ‘default’ alias, not for Lubbock. This is because weather looks up current conditions by station ID, not by city/state. If I pass the station ID instead, I’ll get the information I was looking for:
$ weather -o --id=KLBB Current conditions at Lubbock International Airport (KLBB) Last updated Sep 26, 2007 - 05:53 PM EDT / 2007.09.26 2153 UTC Wind: from the S (170 degrees) at 9 MPH (8 KT) gusting to 18 MPH (16 KT) Sky conditions: mostly cloudy Weather: Cumulonimbus clouds, towering cumulus clouds observed Temperature: 86.0 F (30.0 C) Relative Humidity: 38%
Being a command-line tool, weather lends itself to various automatic processes. For example, you might want to cancel your weekly bicycle pub crawl if the forecast shows a high chance of rain:
$ cat /etc/cron.weekly/pub-reminder #!/bin/sh set -e if weather -f | egrep -q '(100)|([5-9][0-9])% chance of precipitation’; then mailx -s ‘Cancellation’ $PUBCRAWLEES < ~/pub-crawl-cancelled else mailx -s 'Get on your bike' $PUBCRAWLEES < ~/pub-crawl-is-a-go fi
Of course, I’d just recommend a rain jacket.
weather is provided by the weather-util package and is available in Debian ‘etch’, testing and unstable, and Ubuntu ‘edgy’, ‘feisty’ and ‘gutsy’.
Edited to add: for international weather station ids, users can look on this US government website. Thanks hideokuze for the info.
Posted in Debian, Ubuntu | 14 Comments »