Récupérer données météo : afficher historique

Biguiz -  
biguiz Messages postés 206 Statut Membre -
Bonjour à tous et à toutes,
Sur mon site j'affiche la météo de ma ville (températures maxi et mini, image du temps). Cette météo s'actualise toutes les 1-2h. Je souhaiterai récupérer chaque jour les données météo à midi par exemple pour pouvoir afficher sur une page les météos de chaque jour de l'année en historique.
Voici mon code PHP :

<?
setlocale(LC_TIME, "fr_FR"); // ou "fr"

$partner = "";
$ville = "référence de la ville"; $vname="nom de la ville";
$jours = 1;
$url = "http://xoap.weather.com/weather/local/".$ville."?cc=*&unit=s&dayf=".$jours;

// Conversion Fahrenheit->Celsius
function f2c($t) { return round(($t-32)*5/9); }

// Lecture d'un fichier XML
function lit_xml($chaine,$isFile,$item,$champs) {
// on lit le fichier ou la chaîne
if($isFile) $chaine = @file_get_contents($chaine);
if($chaine) {
// on explode sur <item>
$tmp = preg_split("/<\/?".$item.">/",$chaine);
// pour chaque <item>
for($i=1;$i<sizeof($tmp);$i++)
// on lit les champs demandés <champ>
foreach($champs as $champ) {
$tmp2 = preg_split("/<\/?".$champ.">/",$tmp[$i]);
// on ajoute au tableau
$tmp3[$champ][] = trim(@$tmp2[1]);
}
// et on retourne le tableau
return @$tmp3;
}
}

// Extraction primaire
$xml = lit_xml($url,true,"day d=.*",array("hi","low","part p=\"d\"","part p=\"n\""));

// Extraction des icones, messages et du taux d'humidité
for($i=0;$i<$jours;$i++) {
$tmp = preg_split("/<\/?icon>/",$xml["part p=\"d\""][$i]);
$xml["icond"][$i] = $tmp[1];
$tmp = preg_split("/<\/?t>/",$xml["part p=\"d\""][$i]);
$xml["altd"][$i] = $tmp[1];
$tmp = preg_split("/<\/?hmid>/",$xml["part p=\"d\""][$i]);
$xml["hmid"][$i] = $tmp[1];
$tmp = preg_split("/<\/?icon>/",$xml["part p=\"n\""][$i]);
$xml["iconn"][$i] = $tmp[1];
$tmp = preg_split("/<\/?t>/",$xml["part p=\"n\""][$i]);
$xml["altn"][$i] = $tmp[1];
}

?>

Et mon code d'affichage sur ma page :

<table>
<tr>
<td height="25"></td>
</tr>
<? for($i=0;$i<$jours;$i++) { ?>
<tr>
<td>
<table>
<tr>
<td colspan=6 align="center"><strong>
<?=ucfirst(strftime("%A %d %B %Y",time()+$i*24*3600))?>
</strong></td>
</tr>
<tr>
<td colspan=6></td>
</tr>
<tr>
<td background="<?php echo $chemin?>images/meteomin.jpg" height="31" width="30" align="center"><strong><?=($xml["low"][$i]=="N/A")?"N/A":f2c($xml["low"][$i])."°"?></strong></td>
<td width="5" height="31"> </td>
<td background="<?php echo $chemin?>images/meteomax.jpg" height="31" width="30" align="center"><strong><?=($xml["hi"][$i]=="N/A")?"N/A":f2c($xml["hi"][$i])."°"?></strong></td>
<td width="7" height="31"> </td>
<td rowspan="2" width="40" height="40"><img src="<?php echo $chemin?>scripts/parts/img/<?=$xml["icond"][$i]?>.png"
width=40 alt="<?=$xml["altd"][$i]?>"></td>
<td width="8" height="40" rowspan="2"> </td>
</tr>
<tr>
<td colspan="4" height="9"></td>
</tr>
</table>

Je suis à l'écoute de toute solution ou aide, même si je pense qu'il doit s'agir de récupérer les données et les stocker dans une BDD, mais après je vois comment faire, je suis un vrai néophyte en PHP

Merci par avance de votre aide ! ^^
A voir également:

3 réponses

Biguiz
 
relance
3
biguiz Messages postés 206 Statut Membre 35
 
Post dernière relance...
2
biguiz
 
derniere relance
1