#! /usr/bin/perl

#makes things work when run without install
# use lib qw( ../perl-shared/blib/lib ../perl-shared/blib/arch );
# this is for after install
# use lib qw( /usr/lib/perl ../lib/perl );
#use lib qw( /usr/local/test/rrd-tool/lib/perl ../lib/perl );

use RRDs;
my $start=time;
my $htmlpath = "/home/michoux/public_html/meteo/";
#my $rrd = "meteo.rrd";
my $rrdpath = "/home/michoux/rrdtool/";
my $name = "$0";
my $tmpparis;
my $tmptls;
my $temps=600;
#my $temps2=1200;
my $temps2=$temps*2;
$name =~ s/\.pl.*//g;
print $temps2;

print "\n--------------->Temps : ".localtime($start)."<-----------------\n";

print "Interval de temps : ".$temps."\n";

sub Create($)
{

	print "~~~~~~~~".$rrdpath.$src.".rrd~~~~~~~~".$start."~~~~".$temps2."~~~~~~~~~~~~~~~~~~~~~~~~\n";

	print "Creation de l'archive de $src....";
	my ($src)=@nospam;

	RRDs::create ("$rrdpath$src.rrd", "--start",$start-1, "--step",$temps,
			"DS:temp_paris:GAUGE:".$temps2.":U:U",
			"DS:vent_paris:GAUGE:".$temps2.":U:U",
			"DS:humid_paris:GAUGE:".$temps2.":U:U",
			"DS:pres_paris:GAUGE:".$temps2.":U:U",
			"DS:temp_tls:GAUGE:".$temps2.":U:U",
			"DS:vent_tls:GAUGE:".$temps2.":U:U",
			"DS:humid_tls:GAUGE:".$temps2.":U:U",
			"DS:pres_tls:GAUGE:".$temps2.":U:U",
			"RRA:AVERAGE:0.2:1:".$temps2,
			"RRA:AVERAGE:0.2:6:168", # moy sur une heure pour tout une semaine => 6data * 10min = 1h : 24h * 7j = 168
			"RRA:AVERAGE:0.5:12:372", # moy sur 2heures pour tout un mois => 12data * 10min = 2h : 372 = 12 * 31 valeur = 12 valeurs par jour
			"RRA:AVERAGE:0.8:144:365" # moy sur un jour pour un ans => 24h * 6data =144data pour une journee : 365jours (valeurs) par ans.
# 	      "RRA:AVERAGE:0.2:1:".$temps2,
# 	      "RRA:AVERAGE:0.2:6:168", # moy sur une heure pour tout une semaine
# 	      "RRA:AVERAGE:0.5:72:62", # moy sur 1/2 jour pour un mois
# 	      "RRA:AVERAGE:0.8:1008:52" # moy sur une semaine pour un ans
			);
	my $ERROR = RRDs::error;
	die "$0: unable to create `$rrdpath$src.rdd': $ERROR\n" if $ERROR;
	print "Done !\n";
}

sub Update($)
{

	my ($src)=@nospam;

#	/usr/bin/w3m -dump http://fr.weather.yahoo.com/479/index_f.html > /tmp/paris_new.txt
	print "Update de $src...";

	if ($src eq "fr.weather.yahoo.com")
	{
#	print "yahoo\n";
		$tmpparis="/tmp/yahoo_paris.txt";
		$tmptls="/tmp/yahoo_toulouse.txt";
		if ( !system ("/usr/bin/w3m -dump http://fr.weather.yahoo.com/FRXX/FRXX0076/index_c.html > $tmpparis")&&	
				!system ("/usr/bin/w3m -dump http://fr.weather.yahoo.com/FRXX/FRXX0099/index_c.html > $tmptls"))
		{	
			print "\nReception des datas en cours....\n";
# dropt some data into the rrd
			print "Paris:\n";
			my $temp_paris =substr(`cat $tmpparis | tr -d ' ' | grep "°" | head -n 2 | tail -n 1 |sed -e "s/[a-zA-Z.]*\\([0-9\\.\\-]*\\)°.*/\\1/"`, 0, -1);
			print "  Temperature:".$temp_paris."\n";
			my $vent_paris =substr(`cat $tmpparis | grep Vent | cut -f2 -d/ | cut -d " " -f1`, 0, -1);
			print "  Vent:".$vent_paris."\n";
			my $humid_paris=substr(`cat $tmpparis | tr -d ' ' | grep Humidité | cut -d "%" -f1 | cut -d ":" -f2`, 0, -1);
			print "  Humidité:".$humid_paris."\n";
			my $pres_paris =substr(`cat $tmpparis | tr -d ' ' | grep Pression |sed -e"s/.*:\\([0-9]*\\)/\\1/"`, 0, -1);
            if ( !($pres_paris =~ m/^\d+$/) ){
                $pres_paris=1000;
            }
			print "  Pression:".$pres_paris."\n";
			print "Toulouse:\n";
			my $temp_tls =substr(`cat $tmptls | tr -d ' ' | grep "°" | head -n 2 | tail -n 1 |sed -e "s/[a-zA-Z.]*\\([0-9\\.\\-]*\\)°.*/\\1/"`, 0, -1);
			print "  Temperature:".$temp_tls."\n";
			my $vent_tls =substr(`cat $tmptls | grep Vent | cut -f2 -d/ | cut -d " " -f1`, 0, -1);
			print "  Vent:".$vent_tls."\n";
			my $humid_tls=substr(`cat $tmptls | tr -d ' ' | grep Humidité | cut -d "%" -f1 | cut -d ":" -f2`, 0, -1);
			print "  Humidité:".$humid_tls."\n";
			my $pres_tls =substr(`cat $tmptls | tr -d ' ' | grep Pression |sed -e"s/.*:\\([0-9]*\\)/\\1/"`, 0, -1);
            if ( !($pres_tls =~ m/^\d+$/) ){
                $pres_tls=1000;
            }
			print "  Pression:".$pres_tls."\n";
			print "Reception des datas fini !\n\n";

			print $start.":".$temp_paris.":".$vent_paris.":".$humid_paris.":".$pres_paris.":".$temp_tls.":".$vent_tls.":".$humid_tls.":".$pres_tls."\n";
			RRDs::update "$rrdpath"."$src".".rrd", "$start:".$temp_paris.":".$vent_paris.":".$humid_paris.":".$pres_paris.":".$temp_tls.":".$vent_tls.":".$humid_tls.":".$pres_tls || die "$0: unable to update `$rrdpath$src.rdd': $ERROR\n";
			if ($ERROR = RRDs::error) 
			{
				die "$0: unable to update `$rrdpath$src.rdd': $ERROR\n";
			}
		}
	}

	if ($src eq "www.wunderground.com")
	{
#	print "wunderground\n";
		$tmpparis="/tmp/wunderground_paris.txt";
		$tmptls="/tmp/wunderground_toulouse.txt";
		if ( !system ("/usr/bin/wget -q -O $tmpparis http://www.wunderground.com/global/stations/07150.html") && 
				!system ("/usr/bin/wget -q -O $tmptls http://www.wunderground.com/global/stations/07630.html"))
		{	
			print "\nReception des datas en cours....\n";
# dropt some data into the rrd
			print "Paris:\n";
			my $temp_paris =substr(`grep  "<font size=+2 face=arial>" -A 5 $tmpparis |grep "<nobr>.*#176;C"|sed "s/.*<b>\\([[:digit:]]\\+\\)<\\/b>.*/\\1/"`, 0, -1);
			print "  Temperature:".$temp_paris."\n";
			my $vent_paris =substr(`grep  "<tr bgcolor=#FFFFFF><td valign=top>" -A 10 $tmpparis |grep "Wind:" -A 5|grep "<nobr>.*km\\/h"|sed "s/.*<b>\\([[:digit:]]\\+\\)<\\/b>.*/\\1/"`, 0, -1);
			print "  Vent:".$vent_paris."\n";
			my $humid_paris=substr(`grep "Humidity.*%" $tmpparis |sed -e"s/.*<b>\\([[:digit:]]\\+\\)%<\\/b>.*/\\1/"`, 0, -1);
			print "  Humidité:".$humid_paris."\n";
			my $pres_paris =substr(`grep  "<tr bgcolor=#ddeeff><td valign=top>" -A 10 $tmpparis |grep "Pressure:" -A 5|grep "hPa"|sed "s/.*<b>\\([[:digit:]]\\+\\)<\\/b>.*/\\1/"`, 0, -1);
			print "  Pression:".$pres_paris."\n";
			print "Toulouse:\n";
			my $temp_tls =substr(`grep  "<font size=+2 face=arial>" -A 5 $tmptls |grep "<nobr>.*#176;C"|sed "s/.*<b>\\([[:digit:]]\\+\\)<\\/b>.*/\\1/"`, 0, -1);
			print "  Temperature:".$temp_tls."\n";
			my $vent_tls =substr(`grep  "<tr bgcolor=#FFFFFF><td valign=top>" -A 10 $tmptls |grep "Wind:" -A 5|grep "<nobr>.*km\\/h"|sed "s/.*<b>\\([[:digit:]]\\+\\)<\\/b>.*/\\1/"`, 0, -1);
			print "  Vent:".$vent_tls."\n";
			my $humid_tls=substr(`grep "Humidity.*%" $tmptls |sed -e"s/.*<b>\\([[:digit:]]\\+\\)%<\\/b>.*/\\1/"`, 0, -1);
			print "  Humidité:".$humid_tls."\n";
			my $pres_tls =substr(`grep  "<tr bgcolor=#ddeeff><td valign=top>" -A 10 $tmptls |grep "Pressure:" -A 5|grep "hPa"|sed "s/.*<b>\\([[:digit:]]\\+\\)<\\/b>.*/\\1/"`, 0, -1);
			print "  Pression:".$pres_tls."\n";
			print "Reception des datas fini !\n\n";

			print $start.":".$temp_paris.":".$vent_paris.":".$humid_paris.":".$pres_paris.":".$temp_tls.":".$vent_tls.":".$humid_tls.":".$pres_tls."\n";
			RRDs::update "$rrdpath"."$src".".rrd", "$start:".$temp_paris.":".$vent_paris.":".$humid_paris.":".$pres_paris.":".$temp_tls.":".$vent_tls.":".$humid_tls.":".$pres_tls;
			if ($ERROR = RRDs::error) 
			{
				die "$0: unable to update `$rrdpath$src.rdd': $ERROR\n";
			}
			open (INFO,">/tmp/meteo");
			print INFO $temp_paris."\n"; 
			print INFO $vent_paris."\n";
			print INFO $humid_paris."\n";
			print INFO $pres_paris."\n"; 
			print INFO $temp_tls."\n";
			print INFO $vent_tls."\n";
			print INFO $humid_tls."\n";
			print INFO $pres_tls."\n";
		}
	}
	print "Done !\n";
}



sub Graphes($)
{
	my ($src)=@nospam;
	print "Generation des graphes de ".$src." dans $htmlpath ... ";

# temperature:

	RRDs::graph "$htmlpath"."$src"."/temperatures-jour.png",
	"--title", "Temperatures des dernieres 24 heures", 
	"--start", "$start - 24 h",
	"--end", "$start",
	"--color", "GRID#999999",
	"--color", "BACK#BBBBBB",
	"--color", "FONT#000000",
	"--color", "SHADEB#000000",
	"--color", "CANVAS#BBBBBB",
	"--interlace",
	"--vertical-label","°C",
	"--imgformat","PNG",
	"--width=450",
	"--lower-limit","0",
	"DEF:paris=$rrdpath$src.rrd:temp_paris:AVERAGE",
	"DEF:tls=$rrdpath$src.rrd:temp_tls:AVERAGE",
#	  "LINE2:paris#001599:Paris",
	"LINE2:paris#001599:Paris",
	"GPRINT:paris:AVERAGE:Moyenne Paris %1.2lf\\c",
	"LINE2:tls#008800:Toulouse",
#  "COMMENT:\nParis actuellement",
	"GPRINT:tls:AVERAGE:Moyenne Toulouse %1.2lf\\c",
	"HRULE:0#880000:";

	if ($ERROR = RRDs::error) {
		print "ERROR: $ERROR\n";
	};

	RRDs::graph "$htmlpath"."$src"."/temperatures-semaine.png",
	"--title", "Temperatures des derniers 7 jours", 
	"--start", "$start - 1 w",
	"--end", "$start",
	"--color", "GRID#999999",
	"--color", "BACK#BBBBBB",
	"--color", "FONT#000000",
	"--color", "SHADEB#000000",
	"--color", "CANVAS#BBBBBB",
	"--interlace",
	"--vertical-label","°C",
	"--imgformat","PNG",
	"--width=450",
	"--lower-limit","0",
	"DEF:paris=$rrdpath$src.rrd:temp_paris:AVERAGE",
	"DEF:tls=$rrdpath$src.rrd:temp_tls:AVERAGE",
	"LINE1:paris#001599:Paris",
	"GPRINT:paris:AVERAGE:Moyenne Paris %1.2lf\\c",
	"LINE1:tls#008800:Toulouse",
	"GPRINT:tls:AVERAGE:Moyenne Toulouse %1.2lf\\c",
	"HRULE:0#880000:";

	if ($ERROR = RRDs::error) {
		print "ERROR Graph: $ERROR\n";
	}

	RRDs::graph "$htmlpath"."$src"."/temperatures-mois.png",
	"--title", "Temperatures des dernieres 4 semaines", 
	"--start", "$start - 1 m",
	"--end", "$start",
	"--color", "GRID#999999",
	"--color", "BACK#BBBBBB",
	"--color", "FONT#000000",
	"--color", "SHADEB#000000",
	"--color", "CANVAS#BBBBBB",
	"--interlace",
	"--vertical-label","°C",
	"--imgformat","PNG",
	"--width=450",
	"--lower-limit","0",
	"DEF:paris=$rrdpath$src.rrd:temp_paris:AVERAGE",
	"DEF:tls=$rrdpath$src.rrd:temp_tls:AVERAGE",
	"LINE1:paris#001599:Paris",
	"GPRINT:paris:AVERAGE:Moyenne Paris %1.2lf\\c",
	"LINE1:tls#008800:Toulouse",
	"GPRINT:tls:AVERAGE:Moyenne Toulouse %1.2lf\\c",
	"HRULE:0#880000:";
	if ($ERROR = RRDs::error) {
		print "ERROR Graph: $ERROR\n";
	}


	RRDs::graph "$htmlpath"."$src"."/temperatures-annee.png",
	"--title", "Temperatures de la derniere année", 
	"--start", "$start - 1 y",
	"--end", "$start",
	"--color", "GRID#999999",
	"--color", "BACK#BBBBBB",
	"--color", "FONT#000000",
	"--color", "SHADEB#000000",
	"--color", "CANVAS#BBBBBB",
	"--interlace",
	"--vertical-label","°C",
	"--imgformat","PNG",
	"--width=450",
	"--lower-limit","0",
	"DEF:paris=$rrdpath$src.rrd:temp_paris:AVERAGE",
	"DEF:tls=$rrdpath$src.rrd:temp_tls:AVERAGE",
	"LINE1:paris#001599:Paris",
	"GPRINT:paris:AVERAGE:Moyenne Paris %1.2lf\\c",
	"LINE1:tls#008800:Toulouse",
	"GPRINT:tls:AVERAGE:Moyenne Toulouse %1.2lf\\c",
	"HRULE:0#880000:";

	if ($ERROR = RRDs::error) {
		print "ERROR: $ERROR\n";
	};

# vent:

	RRDs::graph "$htmlpath"."$src"."/vent-jour.png",
	"--title", "Vitesse du vent des dernieres 24 heures", 
	"--start", "$start - 24 h",
	"--end", "$start",
	"--color", "GRID#999999",
	"--color", "BACK#BBBBBB",
	"--color", "FONT#000000",
	"--color", "SHADEB#000000",
	"--color", "CANVAS#BBBBBB",
	"--interlace",
	"--imgformat","PNG",
	"--width=450",
	"--vertical-label","Km/h",
	"--lower-limit","0",
	"DEF:paris=$rrdpath$src.rrd:vent_paris:AVERAGE",
	"DEF:tls=$rrdpath$src.rrd:vent_tls:AVERAGE",
	"CDEF:cparis=paris,0,200,LIMIT",
	"CDEF:ctls=tls,0,200,LIMIT",
	"LINE2:cparis#001599:Paris",
	"GPRINT:paris:AVERAGE:Moyenne Paris %2.2lf\\c",
	"LINE2:ctls#008800:Toulouse",
	"GPRINT:tls:AVERAGE:Moyenne Toulouse %2.2lf\\c"
		;
	if ($ERROR = RRDs::error) {
		print "ERROR Graph: $ERROR\n";
	}


	RRDs::graph "$htmlpath"."$src"."/vent-semaine.png",
	"--title", "Vitesse du vent des derniers 7 jours", 
	"--start", "$start - 1 w",
	"--end", "$start",
	"--color", "GRID#999999",
	"--color", "BACK#BBBBBB",
	"--color", "FONT#000000",
	"--color", "SHADEB#000000",
	"--color", "CANVAS#BBBBBB",
	"--interlace",
	"--imgformat","PNG",
	"--width=450",
	"--vertical-label","Km/h",
	"--lower-limit","0",
	"DEF:paris=$rrdpath$src.rrd:vent_paris:AVERAGE",
	"DEF:tls=$rrdpath$src.rrd:vent_tls:AVERAGE",
	"LINE1:paris#001599:Paris",
	"GPRINT:paris:AVERAGE:Moyenne Paris %2.2lf\\c",
	"LINE1:tls#008800:Toulouse",
	"GPRINT:tls:AVERAGE:Moyenne Toulouse %2.2lf\\c"
		;
	if ($ERROR = RRDs::error) {
		print "ERROR Graph: $ERROR\n";
	}


	RRDs::graph "$htmlpath"."$src"."/vent-mois.png",
	"--title", "Vitesse du vent des dernieres 4 semaines", 
	"--start", "$start - 1 m",
	"--end", "$start",
	"--color", "GRID#999999",
	"--color", "BACK#BBBBBB",
	"--color", "FONT#000000",
	"--color", "SHADEB#000000",
	"--color", "CANVAS#BBBBBB",
	"--interlace",
	"--imgformat","PNG",
	"--width=450",
	"--vertical-label","Km/h",
	"--lower-limit","0",
	"DEF:paris=$rrdpath$src.rrd:vent_paris:AVERAGE",
	"DEF:tls=$rrdpath$src.rrd:vent_tls:AVERAGE",
	"LINE1:paris#001599:Paris",
	"GPRINT:paris:AVERAGE:Moyenne Paris %2.2lf\\c",
	"LINE1:tls#008800:Toulouse",
	"GPRINT:tls:AVERAGE:Moyenne Toulouse %2.2lf\\c"
		;
	if ($ERROR = RRDs::error) {
		print "ERROR Graph: $ERROR\n";
	}


	RRDs::graph "$htmlpath"."$src"."/vent-annee.png",
	"--title", "Vitesse du vent de la derniere année", 
	"--start", "$start - 1 y",
	"--end", "$start",
	"--color", "GRID#999999",
	"--color", "BACK#BBBBBB",
	"--color", "FONT#000000",
	"--color", "SHADEB#000000",
	"--color", "CANVAS#BBBBBB",
	"--interlace",
	"--imgformat","PNG",
	"--width=450",
	"--vertical-label","Km/h",
	"--lower-limit","0",
	"DEF:paris=$rrdpath$src.rrd:vent_paris:AVERAGE",
	"DEF:tls=$rrdpath$src.rrd:vent_tls:AVERAGE",
	"LINE1:paris#001599:Paris",
	"GPRINT:paris:AVERAGE:Moyenne Paris %2.2lf\\c",
	"LINE1:tls#008800:Toulouse",
	"GPRINT:tls:AVERAGE:Moyenne Toulouse %2.2lf\\c"
		;
	if ($ERROR = RRDs::error) {
		print "ERROR Graph: $ERROR\n";
	}


#humidité

	RRDs::graph "$htmlpath"."$src"."/humidite-jour.png",
	"--title", "Humidité des dernieres 24 heures", 
	"--start", "$start - 24 h",
	"--end", "$start",
	"--color", "GRID#999999",
	"--color", "BACK#BBBBBB",
	"--color", "FONT#000000",
	"--color", "SHADEB#000000",
	"--color", "CANVAS#BBBBBB",
	"--interlace",
	"--imgformat","PNG",
	"--width=450",
	"--vertical-label","%",
	"DEF:paris=$rrdpath$src.rrd:humid_paris:AVERAGE",
	"DEF:tls=$rrdpath$src.rrd:humid_tls:AVERAGE",
	"CDEF:cparis=paris,2,100,LIMIT",
	"CDEF:ctls=tls,2,100,LIMIT",
	"LINE2:cparis#001599:Paris",
	"GPRINT:paris:AVERAGE:Moyenne Paris %2.2lf\\c",
	"LINE2:ctls#008800:Toulouse",
	"GPRINT:tls:AVERAGE:Moyenne Toulouse %2.2lf\\c"
		;

	if ($ERROR = RRDs::error) {
		print "ERROR Graph: $ERROR\n";
	}

	RRDs::graph "$htmlpath"."$src"."/humidite-semaine.png",
	"--title", "Humidité des derniers 7 jours", 
	"--start", "$start - 1 w",
	"--end", "$start",
	"--color", "GRID#999999",
	"--color", "BACK#BBBBBB",
	"--color", "FONT#000000",
	"--color", "SHADEB#000000",
	"--color", "CANVAS#BBBBBB",
	"--interlace",
	"--imgformat","PNG",
	"--width=450",
	"--vertical-label","%",
	"DEF:paris=$rrdpath$src.rrd:humid_paris:AVERAGE",
	"DEF:tls=$rrdpath$src.rrd:humid_tls:AVERAGE",
	"LINE1:paris#001599:Paris",
	"GPRINT:paris:AVERAGE:Moyenne Paris %2.2lf\\c",
	"LINE1:tls#008800:Toulouse",
	"GPRINT:tls:AVERAGE:Moyenne Toulouse %2.2lf\\c"
		;

	if ($ERROR = RRDs::error) {
		print "ERROR Graph: $ERROR\n";
	}

	RRDs::graph "$htmlpath"."$src"."/humidite-mois.png",
	"--title", "Humidité des dernieres 4 semaines", 
	"--start", "$start - 1 m",
	"--end", "$start",
	"--color", "GRID#999999",
	"--color", "BACK#BBBBBB",
	"--color", "FONT#000000",
	"--color", "SHADEB#000000",
	"--color", "CANVAS#BBBBBB",
	"--interlace",
	"--imgformat","PNG",
	"--width=450",
	"--vertical-label","%",
	"DEF:paris=$rrdpath$src.rrd:humid_paris:AVERAGE",
	"DEF:tls=$rrdpath$src.rrd:humid_tls:AVERAGE",
	"LINE1:paris#001599:Paris",
	"GPRINT:paris:AVERAGE:Moyenne Paris %2.2lf\\c",
	"LINE1:tls#008800:Toulouse",
	"GPRINT:tls:AVERAGE:Moyenne Toulouse %2.2lf\\c"
		;

	if ($ERROR = RRDs::error) {
		print "ERROR Graph: $ERROR\n";
	}

	RRDs::graph "$htmlpath"."$src"."/humidite-annee.png",
	"--title", "Humidité de la derniere année", 
	"--start", "$start - 1 y",
	"--end", "$start",
	"--color", "GRID#999999",
	"--color", "BACK#BBBBBB",
	"--color", "FONT#000000",
	"--color", "SHADEB#000000",
	"--color", "CANVAS#BBBBBB",
	"--interlace",
	"--imgformat","PNG",
	"--width=450",
	"--vertical-label","%",
	"DEF:paris=$rrdpath$src.rrd:humid_paris:AVERAGE",
	"DEF:tls=$rrdpath$src.rrd:humid_tls:AVERAGE",
	"LINE1:paris#001599:Paris",
	"GPRINT:paris:AVERAGE:Moyenne Paris %2.2lf\\c",
	"LINE1:tls#008800:Toulouse",
	"GPRINT:tls:AVERAGE:Moyenne Toulouse %2.2lf\\c"
		;

	if ($ERROR = RRDs::error) {
		print "ERROR Graph: $ERROR\n";
	}

# Pression

	RRDs::graph "$htmlpath"."$src"."/pression-jour.png",
	"--title", "Pression des dernieres 24 heures", 
	"--start", "$start - 24 h",
	"--end", "$start",
	"--color", "GRID#999999",
	"--color", "BACK#BBBBBB",
	"--color", "FONT#000000",
	"--color", "SHADEB#000000",
	"--color", "CANVAS#BBBBBB",
	"--interlace",
	"--imgformat","PNG",
	"--width=450",
	"--vertical-label","hPa",
	"DEF:paris=$rrdpath$src.rrd:pres_paris:AVERAGE",
	"DEF:tls=$rrdpath$src.rrd:pres_tls:AVERAGE",
	"CDEF:cparis=paris,800,1200,LIMIT",
	"CDEF:ctls=tls,800,1200,LIMIT",
	"LINE2:cparis#001599:Paris",
	"GPRINT:paris:AVERAGE:Moyenne Paris %2.2lf\\c",
	"LINE2:ctls#008800:Toulouse",
	"GPRINT:tls:AVERAGE:Moyenne Toulouse %2.2lf\\c"
		;

	if ($ERROR = RRDs::error) {
		print "ERROR Graph: $ERROR\n";
	}

	RRDs::graph "$htmlpath"."$src"."/pression-semaine.png",
	"--title", "Pression des derniers 7 jours", 
	"--start", "$start - 1 w",
	"--end", "$start",
	"--color", "GRID#999999",
	"--color", "BACK#BBBBBB",
	"--color", "FONT#000000",
	"--color", "SHADEB#000000",
	"--color", "CANVAS#BBBBBB",
	"--interlace",
	"--imgformat","PNG",
	"--width=450",
	"--vertical-label","hPa",
	"DEF:paris=$rrdpath$src.rrd:pres_paris:AVERAGE",
	"DEF:tls=$rrdpath$src.rrd:pres_tls:AVERAGE",
	"LINE1:paris#001599:Paris",
	"GPRINT:paris:AVERAGE:Moyenne Paris %2.2lf\\c",
	"LINE1:tls#008800:Toulouse",
	"GPRINT:tls:AVERAGE:Moyenne Toulouse %2.2lf\\c"
		;

	if ($ERROR = RRDs::error) {
		print "ERROR Graph: $ERROR\n";
	}

	RRDs::graph "$htmlpath"."$src"."/pression-mois.png",
	"--title", "Pression des dernieres 4 semaines", 
	"--start", "$start - 1 m",
	"--end", "$start",
	"--color", "GRID#999999",
	"--color", "BACK#BBBBBB",
	"--color", "FONT#000000",
	"--color", "SHADEB#000000",
	"--color", "CANVAS#BBBBBB",
	"--interlace",
	"--imgformat","PNG",
	"--width=450",
	"--vertical-label","hPa",
	"DEF:paris=$rrdpath$src.rrd:pres_paris:AVERAGE",
	"DEF:tls=$rrdpath$src.rrd:pres_tls:AVERAGE",
	"LINE1:paris#001599:Paris",
	"GPRINT:paris:AVERAGE:Moyenne Paris %2.2lf\\c",
	"LINE1:tls#008800:Toulouse",
	"GPRINT:tls:AVERAGE:Moyenne Toulouse %2.2lf\\c"
		;

	if ($ERROR = RRDs::error) {
		print "ERROR Graph: $ERROR\n";
	}

	RRDs::graph "$htmlpath"."$src"."/pression-annee.png",
	"--title", "Pression de la derniere année", 
	"--start", "$start - 1 y",
	"--end", "$start",
	"--color", "GRID#999999",
	"--color", "BACK#BBBBBB",
	"--color", "FONT#000000",
	"--color", "SHADEB#000000",
	"--color", "CANVAS#BBBBBB",
	"--interlace",
	"--imgformat","PNG",
	"--width=450",
	"--vertical-label","hPa",
	"DEF:paris=$rrdpath$src.rrd:pres_paris:AVERAGE",
	"DEF:tls=$rrdpath$src.rrd:pres_tls:AVERAGE",
	"LINE1:paris#001599:Paris",
	"GPRINT:paris:AVERAGE:Moyenne Paris %2.2lf\\c",
	"LINE1:tls#008800:Toulouse",
	"GPRINT:tls:AVERAGE:Moyenne Toulouse %2.2lf\\c"
		;

	if ($ERROR = RRDs::error) {
		print "ERROR Graph: $ERROR\n";
	}
	print "Done !\n";
}

#Create("www.wunderground.com");
Update("www.wunderground.com");
Graphes("www.wunderground.com");

#Create("fr.weather.yahoo.com");
Update("fr.weather.yahoo.com");
Graphes("fr.weather.yahoo.com");
