Table des matières

Conky : météo

Fichier conkyrc

~/.conky/conkyrc-M
background yes
 
use_xft yes
xftalpha 0.8
xftfont Bitstream Vera Sans Mono:size=8
 
own_window yes
own_window_class conky
own_window_argb_visual yes
own_window_hints undecorate,sticky,skip_taskbar,skip_pager,below
own_window_transparent yes
 
double_buffer yes
no_buffers yes
 
minimum_size 356 700
maximum_width 356
 
alignment tr
 
override_utf8_locale yes
 
default_color slategrey
 
TEXT
${color lightgrey}Météo
${execi 120 ~/.conky/scripts/meteo.sh CODE-LIEU}
${color}Aujourd'hui: ${color lightgrey}${execi 120 ~/.conky/scripts/meteo2p.sh "Température aujourd'hui"}, ${execi 120 ~/.conky/scripts/meteo2p.sh "Conditions aujourd'hui"}
${color}Vent: ${color lightgrey}${execi 120 ~/.conky/scripts/meteo2p.sh "Vent aujourd'hui"}
${color}Demain: ${color lightgrey}${execi 120 ~/.conky/scripts/meteo2p.sh "Température demain"}, ${execi 120 ~/.conky/scripts/meteo2p.sh "Conditions demain"}
 
${color}Lever du soleil: ${color lightgrey}${execi 120 ~/.conky/scripts/meteo2p.sh "Lever du soleil"}   ${color}Coucher du soleil: ${color lightgrey}${execi 120 ~/.conky/scripts/meteo2p.sh "Coucher du soleil"}

Script Shell 1

~/.conky/scripts/meteo.sh
#!/bin/bash
 
# Répertoire de ce script et du XSLT
RUNDIR=~/.conky
# Emplacement du XSLT
XSLT=$RUNDIR/meteo.xslt
# Fichier de destination des informations
DESTFILE=/tmp/conky_meteo.txt
# Emplacement de xsltproc
XSLTCMD=/usr/bin/xsltproc
 
# Traitement
URL="http://xml.weather.com/weather/local/$1?cc=*&unit=m&dayf=2"
w3m -dump $URL | $XSLTCMD $XSLT - > $DESTFILE

Script Shell 2

~/.conky/scripts/meteo2p.sh
#!/bin/bash
 
# Fichier où sont stockées les informations
SRCFILE=/tmp/conky_meteo.txt
 
# Traitement
RESULTAT=$(grep "$1" $SRCFILE | awk -F " : " '{print $2}')
 
# Transformation de la condition en lettre qui deviendra une icône
if echo "$1" | grep -i -q 'condition'; then
	  if echo "$RESULTAT" | grep -i -q 'partly cloudy'; then
		RESULTAT='ciel voilé'
	elif echo "$RESULTAT" | grep -i -q 'mostly cloudy'; then
		RESULTAT='plutôt nuageux'
	elif echo "$RESULTAT" | grep -i -q 'clear'; then
		RESULTAT='clair'
	elif echo "$RESULTAT" | grep -i -q 'fair'; then
		RESULTAT='beau'
	elif echo "$RESULTAT" | grep -i -q 'sunny'; then
		RESULTAT='ensoleillé'
	elif echo "$RESULTAT" | grep -i -q 'cloudy'; then
		RESULTAT='nuageux'
	elif echo "$RESULTAT" | grep -E -i -q 'storm|thunder'; then
		RESULTAT='tempête'
	elif echo "$RESULTAT" | grep -i -q 'snow'; then
		RESULTAT='neige'
	elif echo "$RESULTAT" | grep -i -q 'rain'; then
		RESULTAT='pluie'
	elif echo "$RESULTAT" | grep -i -q 'shower'; then
		RESULTAT='averses'
	fi
 
# Transformation des heures à l'américaine (5:50 AM) en heures à la française (5h50)
elif echo "$1" | grep -i -q 'soleil'; then
	RESULTAT=$(echo "$RESULTAT" | awk '{print $1}' | sed -e s/:/h/g)
 
	# Transformation des heures PM (9h38 PM) en heures françaises (21h38)
	if echo "$1" | grep -i -q 'coucher'; then
		HEURES=$(echo "$RESULTAT" | awk -F "h" '{print $1}')
		MINUTES=$(echo "$RESULTAT" | awk -F "h" '{print $2}')
		HEURES=$(($HEURES + 12))
		RESULTAT="${HEURES}h${MINUTES}"
	fi
 
# Transformation de "Ville, Pays" en "Ville"
elif echo "$1" | grep -i -q 'ville'; then
	RESULTAT=$(echo "$RESULTAT" | awk -F "," '{print $1}')
 
fi
 
# Affichage du résultat
echo $RESULTAT

Feuille de style XSLT

~/.conky/meteo.xslt
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" >
        <xsl:output method="text" disable-output-escaping="yes"/>
        <xsl:template match="weather">
        	<xsl:text>Ville : </xsl:text><xsl:value-of select="/weather/loc/dnam"/>
                <xsl:apply-templates select="cc"/>
                <xsl:apply-templates select="dayf/day[@d='1']"/>
                <xsl:text>
Lever du soleil : </xsl:text><xsl:value-of select="/weather/loc/sunr"/>
		<xsl:text>
Coucher du soleil : </xsl:text><xsl:value-of select="/weather/loc/suns"/>
        </xsl:template>
 
        <xsl:template match="cc">
<xsl:text>
Température aujourd'hui : </xsl:text><xsl:value-of select="tmp"/>°<xsl:value-of select="/weather/head/ut"/>
<xsl:if test="tmp != flik">
<xsl:text> (</xsl:text>
<xsl:value-of select="flik"/>°<xsl:value-of select="/weather/head/ut"/>
<xsl:text> ressenti)</xsl:text>
</xsl:if>
<xsl:text>
Conditions aujourd'hui : </xsl:text><xsl:value-of select="t"/>
<xsl:text>
Vent aujourd'hui : </xsl:text>
<xsl:choose>
<xsl:when test="wind/s = 'calm'"><xsl:text>0</xsl:text></xsl:when>
<xsl:otherwise><xsl:value-of select="wind/s"/></xsl:otherwise>
</xsl:choose>
<xsl:text> </xsl:text>
<xsl:value-of select="/weather/head/us"/>
</xsl:template>
 
<xsl:template match="dayf/day[@d='1']">
<xsl:text>
Température demain : de </xsl:text><xsl:value-of select="low"/>°<xsl:value-of select="/weather/head/ut"/>
<xsl:text> à </xsl:text><xsl:value-of select="hi"/>°<xsl:value-of select="/weather/head/ut"/>
<xsl:text>
Conditions demain : </xsl:text><xsl:value-of select="part[@p='d']/t"/>
</xsl:template>
</xsl:stylesheet>