Give icons to your weather


29.07.2009 | Categories: Ubuntu


How to graphically display weather info with Conky

As some of you may know, the new version of Conky will include built-in support for weather.

In this blog post, I'm going to talk about how to use this info to make an image for the current weather to be displayed to your desktop:

Lua and weather example

With weather enabled (use --enable-weather-metar or --enable-weather-xoap during the configuration step), you can get cloud cover and weather status by using the ${weather uri locid cloud_cover} and ${weather uri locid weather} directives. Lets concentrate for the time being on the weather metar data from the NWS (this will apply also to the weather info from weather.com but I plan to introduce upstream a new icon directive that will make it even easier for that).

The possible return values for cloud_cover are:

Those for weather are:

The first thing to do is to find icons for those various weather states. There are plenty of good and free icons to be found on the internet, alternatively, if you register to the www.weather.com service you will get a complete set that matches their weather states.

You don't need an icon for each and every state, you can obviously collect various states together, like a snow icon for snow and snow grains, a rain icon for drizzle, rain, hail and soft hail, an overcast icon for overcast, towering cumulus and cumulonimbus etc.

Save the icons in a directory of your choice, and name them in accordance with the state they represent.
To retrieve the weather status we use a lua function. This lua function takes as input the icao of the station we want data for, evaluates the weather directives and construct the name of the icon we want to display in accordance to a set of rules. In the simple example I'm going to show, it is just using the cloud_cover returned as the icon name. Since this can also be a null string, we need to add an icon to cover for this case.

function conky_show_icon(icao)
	 local type
	 type = conky_parse("${weather 
	      http://weather.noaa.gov/pub/data/observations/metar/stations/ "
	      .. icao .. " cloud_cover}")
	 if type ~= "" then 
	    type = "${image /home/cesare/icons/" .. type .. ".png -p 0,30 -f 1800}"
	 else
	    type = "${image /home/cesare/icons/null.png -p 0,30 -f 1800}"
	 end
	 return type
end

Save this lua script in your root directory as weather_icons.lua.
We are almost set, all we need now is to add the following to our configuration file:

lua_load ~/weather_icons.lua
TEXT
${lua_parse conky_show_icon LIRA}

Substitude LIRA with your icao of choice and voilá! Hopefully a sunny face will show up on your desktop too.

Comments