You are not logged in.
Pages: 1
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
Offline
Yeah, well, I already read that. And it's not exactly what I want.
Offline
<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
Nice! That's the idea.
Could you explain what the command does exactly?
Offline
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
Thanks! I didn't know about xmlstarlet, I'm reading the documentation.
Offline
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
Thanks for the suggestion!
Offline
Pages: 1