A script to display weather forecast for conky
Conky is undoubtedly the most configurable, versatile and amazing program I have ever come across. With very little effort you can get a very sleek looking desktop. I have seen people using it to display all kinds of information under the sky. Although, it can only display pure text, there is a possibility to use different symbolic fonts to display text based images. Moreover, it is also very efficient program. Its own footprint is very small compared to most of the gadget frameworks like adesklets, gDesklets and of course plasma. Configuration is also relatively easy. The best way is to copy configuration file from some one else and keep on changing it until you get what you want. Another application worth mentioning here is dzen2. Dzen2 has ability to render any text graphically, although it lacks the built in variables of conky. In archlinux there is an application package called conky-cli which is a stripped down version of conky without X11 dependency. A combination of conky-cli and dzen2 is then used to make taskbars for minimalistic desktops like xmonad, wmii, dwm etc. Personally, I haven’t tried this combination yet.
Ubuntu and Archlinux forums have dedicated threads with conky screen shots and config files. I came across many screen shots with weather information, forecast and small symbols with weather conditions. Most of them were using a perl script (for which I cannot find the link now) to fetch, parse and show the weather information from weather.com. The weather symbols were ttf fonts. I didn’t want to take the script one-to-one and perl is anyway too cryptic for me to decipher. I decided to take the concept and develop something similar on my own.
So I created the google weather script. It is a simple bash script to fetch the xml file using google weather api, I changed the source because although weather.com was providing good information, they were changing the format of the request too often, their terms and conditions of usage were also not very comprehensible for me. Then I use different style-sheets to process the xml response and show different information depending on the argument passed to the bash script. I also use the weather.ttf fonts to render the symbols for different weather conditions. For transforming xml, I use the xsltproc tool.
Here is the conky running under kde4 desktop. With different desktop environments conky needs to be adjusted a bit. Another weakness of conky in integrating external scripts is that the output must be pre-formatted before supplying it to conky. Conky just takes the text and renders it. In principle any executable can be called from conky to display its output.
Conky has many built-in variables for displaying common system parameters which are well documented on the official documentation page. Besides the common parameters like cpu / memory usage, uptime, upload-download speed, top 3 cpu using processes and top 3 memory using processes, the screen shot on the left also displays the dictionry.com word of the day rss feed, which I find extremely useful. It also uses a similar script and xslt transformation. There is also a built-in rss feed processor in conky.
I use mpd for playing music. There is also built-in mpd support in conky and can be used to display information about current song being played. If you want to show different information at different places on the desktop, it is also possible to have multiple instances of conky running at the same time with different configuration files.
As evident in the screen shot it is difficult to adjust the spacing of the weather output due to mixing of different types and sizes of fonts. My script only considers some frequent weather conditions, but it can easily adapted to support many different weather conditions. The spacing must be adjusted for individual setup by editing the line no. 16 in the file fcConditions.xslt
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" > <xsl:include href="conditionsInclude.xslt"/> <xsl:output method="text" disable-output-escaping="yes" encoding="utf-8"/> <xsl:template match="xml_api_reply"> <xsl:apply-templates select="weather"/> </xsl:template> <xsl:template match="weather"> <xsl:for-each select="forecast_conditions[position() >= 2]"> <xsl:call-template name="get-condition-symbol"> <xsl:with-param name="condition"> <xsl:value-of select="condition/@data"/> </xsl:with-param> </xsl:call-template> <xsl:if test="position() != 3"> <xsl:text> </xsl:text> </xsl:if> </xsl:for-each> </xsl:template> </xsl:stylesheet>
I have hard-coded the update interval to 1 hour. This can also be changed very easily to the required value by changing the value of the update variable in the weather.sh file.
# don't get the file if created within an hour update=3600
I use mainly following configurations for conky.
I have released the script with GPL V3 license, so feel free to use it if you like it. Please comment about any bug reports, improvements, questions or suggestions.
great work.