You are not logged in.

#1 2013-11-22 13:07:04

Lala0KjOA
Member
Registered: 2011-12-23
Posts: 123
Website

Help for a Conky weather script

Hi,

I was trying to write a Conky script to display weather forecast for the current day in my Conky, using <tempmin>, <tempmax> and <descr> on this page http://www.tv5.org/TV5Site/widget/meteo … lle_id=474.
I'm a complete newbie to bash/perl/whatever, and I couldn't manage to do much. Could anyone explain me how to proceed?

Please don't RTFM me :(

Offline

#2 2013-11-22 13:23:10

cris9288
Member
Registered: 2013-01-07
Posts: 347

Re: Help for a Conky weather script

Offline

#3 2013-11-22 13:31:38

Lala0KjOA
Member
Registered: 2011-12-23
Posts: 123
Website

Re: Help for a Conky weather script

Yeah, well, I already read that. And it's not exactly what I want.

Offline

#4 2013-11-22 14:06:47

karol
Archivist
Registered: 2009-05-06
Posts: 25,431

Re: Help for a Conky weather script

<item date="vendredi 22">
  <libmin>Matin</libmin>
  <tempmin>2°C</tempmin>
  <libmax>Après-midi</libmax>
  <tempmax>5°C</tempmax>
  <descr>très nuageux </descr>

gets translated by

$ echo -e $(xml sel --net -t -m '//tempmin[1]' -v . -o "\n" -m '//tempmax[1]' -v . -o "\n" -m '//descr[2]' -v . -n http://www.tv5.org/TV5Site/widget/meteotv5_weather.php?ville_id=474)

into

2°C
5°C
très nuageux

Is this how you want it?

Offline

#5 2013-11-22 14:18:33

Lala0KjOA
Member
Registered: 2011-12-23
Posts: 123
Website

Re: Help for a Conky weather script

Nice! That's the idea.

Could you explain what the command does exactly?

Offline

#6 2013-11-22 14:25:58

karol
Archivist
Registered: 2009-05-06
Posts: 25,431

Re: Help for a Conky weather script

You need xmlstarlet to run it.
It simply parses that xml file and extracts the info you want.
I wanted to add newlines, so I just wrapped it all in 'echo -e $(...)' and called it a day. There's probably a better way to do it.
Also, note that the index on 'descr' is one higher than on 'tempmin' and 'tempmax', because there's already a 'descr' earlier in the file:

<weather>
  <data>
    <ville>Paris</ville>
    <pays>FRANCE</pays>
    <date>Observation le vendredi 22 à 13:00 (heure locale)</date>
    <temp>4°C</temp>
    <descr>couvert </descr>

You don't want the value of this 'descr', but of the one a bit lower (the second one) -

<descr>très nuageux </descr>

thus '//descr[2]'.

Offline

#7 2013-11-22 16:52:59

Lala0KjOA
Member
Registered: 2011-12-23
Posts: 123
Website

Re: Help for a Conky weather script

Thanks! I didn't know about xmlstarlet, I'm reading the documentation.

Offline

#8 2013-11-24 03:51:49

rockin turtle
Member
From: Montana, USA
Registered: 2009-10-22
Posts: 218

Re: Help for a Conky weather script

You could modify the following script to suit your needs.

You need package libxml2 for xmllint.

#!/usr/bin/bash

url='http://www.tv5.org/TV5Site/widget/meteotv5_weather.php?ville_id=474'
xml=$(wget -q -O - "$url")

min=$(xmllint --xpath 'string(weather/forecast/item[1]/tempmin)' - <<< "$xml")
max=$(xmllint --xpath 'string(weather/forecast/item[1]/tempmax)' - <<< "$xml")
descr=$(xmllint --xpath 'string(weather/forecast/item[1]/descr)' - <<< "$xml")

echo "$min - $max:  $descr"

Then in your TEXT section of your .conkyrc file put:

${exec script}

but replace 'script' with the filename of the above script.

Offline

#9 2013-11-24 13:03:44

Lala0KjOA
Member
Registered: 2011-12-23
Posts: 123
Website

Re: Help for a Conky weather script

Thanks for the suggestion!

Offline

Board footer

Powered by FluxBB