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.
A weather plasmoid in python « cout 9:03 pm on August 13, 2009 Permalink |
[...] layout is based on my conky setup described here. I have tried to keep it as compact as possible including most of the provided information, if not [...]
antibalas 4:40 am on October 30, 2009 Permalink |
great work.
foenOsteotNox 12:17 am on December 11, 2009 Permalink |
I’m often searching for recent blogposts in the WWW about this issue. Thx!
webrev 7:13 pm on August 6, 2010 Permalink |
Love the google weather script. Thanks. Can someone tell me how to change the temp units to standard. I have changed in weather.sh
UNITS=s
But it still reports as metric.
hardikmehta 8:16 pm on August 6, 2010 Permalink |
Hi,
Thanks for using the script. The UNITS variable is obsolete with the google api implementation. It worked with the weather.com version.
With google apis, it is a bit different. The default locale of the url is “us” which is used in the script. In this case the temperatures are provided in both metric and standard units. See temp_c elements in the xml http://www.google.com/ig/api?weather=Munich,Germany
If you want a localized output please append hl=[iso locale code] to the url, but then the output is also in the language specifed by the locale, so the script is not guranteed wo to work with it.
example of German locale (de)
http://www.google.com/ig/api?weather=Munich,Germany&hl=de
I hope this helps. Feel free to ask if you have further questions.
Ben Brown 5:54 pm on February 23, 2011 Permalink |
Just wanted to let know how much I appreciate the work you did on the weather program for conky. I don’t understand all the programs and coding, but I am working my way through the code and have been able to get it to work for me here in Michigan, USA.
Again, thank you so much for sharing this with the community.
hardikmehta 6:01 pm on February 23, 2011 Permalink |
Hi, Thanks. Glad that it worked for you.
Agnelo de la Crotche 2:26 pm on May 21, 2011 Permalink |
Great job! What about packaging it for different distros in OBS (https://build.opensuse.org) ?