Код отслеживания Google Analytics.

Jan 5, 2011

weather from gismeteo for conky

Well after conky was successful started(My conky) we can add some fun. I've chosen the weather - it is standart part of almost all conky config.

At first let me change my auto-start conky script:
#!/bin/bash

echo conky will be started after a half of minute 
sleep 30
killall conky
/usr/bin/conky --daemonize
/usr/bin/conky --daemonize --config=<your home dir>/bin/conky/weatherConky.rc
sleep 1 #we need a second the window to be created
for winID in $(wmctrl -l | sed -n "s|^\([^[:space:]]*\).*Conky (${HOSTNAME}).*$|\1|gp"); do
    wmctrl -i -r "${winID}" -t 3
done
I've just add one more instance of conky and change part of moving windows to workplace4 (number - 3) - now it moves by window ID.

The weatherConky.rc is very similar to default ~/.conkyrc in most. But some changes are important:
  • we don't need often update weather conky on the screen. But from other hand using update number is the trick for simple animation (details are here and bellow) and can not be to large.
  • update_interval 3.0
    
  • as we use a script for content generate we need large buffer
  • text_buffer_size 8192 #256 by default is too small for getGismeteo.sh script
  • we have to switch off image cache for weather icon animation.
  • imlib_cache_size 0
    
  • the only string in "TEXT" part of config
  • TEXT
    ${execpi 180 <your home dir>/bin/conky/getGismeteo.sh -ct 4079,4944,744 -n 3}
    
So, as you can see, all content for conky is produced by getGismeteo.sh. This script uses my shell framework library:

$~/bin/conky/getGismeteo.sh --help

This script get and parse weather data from http://www.gismeteo.ru/
Usage: <your home dir>/bin/conky/getGismeteo.sh [option(s)] [command]
Options:
 -h|--help print this help
 --help-options print detailed description of options using
 -l <parameter>|--shF_logLevel=<parameter> define the current log level (<parameter>). You can use the following number - 0(shF_EVERYTHING), 1(shF_DEBUG), 2(shF_INFO), 3(shF_HIGH), 4(shF_WARN), 5(shF_ERROR). Config name is shF_currentLogLevel. Default value is "2".
 --logFile=<parameter> define the <parameter> as log stream. You can use stdError, stdOut or file name. Config name is shF_currentLogFile. Default value is "stdError".
 -c <parameter>|--config=<parameter> define the <parameter> as property file which will be loaded.
 -p|--print-config print the current configuration.
 -t <parameter>|--cache=<parameter> <parameter> is time in minutes. All files older then the time in cache will be reloaded. 0 - cache will not used (is not recomended) Config name is cacheTime. Default value is "360".
 -ct <parameter>|--cities=<parameter> <parameter> is string of city code separated by comma. You need define at least one Config name is cities.
 -n <parameter>|--days=<parameter> <parameter> is number of days report about (0 - maximum). Config name is days. Default value is "0".
All except 3 last are very regular. -t define how long files will be valid in cache directory, -c - list of cities - in my case St.Petersburg, Kiev and London(4079,4944,744 -you can find them at http://www.gismeteo.ru/) and -n - number of days you need generate report (up to 14).
I think the algorithm is obvious and don't need be paid attention a lot. The interesting is animation. At first after images downloaded from gismeteo I've change them by adding some text. Theimage magic is absolutely amazing tool:
weekDay=$(date -d "${actualDate}" '+%a')
        convert "${imageFile}" \
            -gravity center -fill blue -annotate 0 "${dayTime}" \
            -gravity northwest -fill black -annotate +1+1 "${weekDay}" \
            -gravity northwest -fill white -annotate 0 "${weekDay}" \
            "${annotatedImageFile}"
where weekDay is short name for day of week(Mon, Tue etc.), dayTime - Morning, Day, Evening (in Russian in my case). Two times writing is the simplest way to create shadow.
At second we have to associate every image with update number in conky:
imageStr="\${if_updatenr ${updateNumber}}\${image ${imageFile} -p 10,${yCoordinate} -s 55x55}\${endif}"
in result it will produce something like this:
${if_updatenr 1}${image <your home dir>/bin/conky/cache/2011-01-06_Ночь_n.moon.c4.r2.png -p 10,600 -s 55x55}${endif}${if_updatenr 2}${image <your home dir>/bin/conky/cache/2011-01-06_Утро_d.sun.c3.r2.png -p 10,600 -s 55x55}${endif}${if_updatenr 3}${image <your home dir>/bin/conky/cache/2011-01-06_День_d.sun.c4.r3.png -p 10,600 -s 55x55}${endif}${if_updatenr 4}${image <your home dir>/bin/conky/cache/2011-01-06_Вечер_n.moon.c4.r3.png -p 10,600 -s 55x55}${endif}
as it was described here. The animated gif you can find under this link (don't forget about 3 seconds delay between images).

2 comments:

nils said...

Hi! I've just stumbled upon your first .conkyrc entry, looks great so far- i want to tweak my conkyrc a bit, so could you explain how to include the scripts mentioned in the first post as one can no longer access your .conkyrc-link you posted there. otherwise i'll try to figure it out for myself.
greetings,
nils

Beggy said...

Hi Nils. Thank you - it was error :) I've fixed it and now you can download it. Please note my .conckyrc contains instead path to your home directory - don't forget to correct it.