à partir du site web http://www.calendrier-lunaire.fr/lune/
- Code : Tout sélectionner
<?php
setlocale(LC_TIME, "fr_FR"); // ou "fr"
$url = "http://www.calendrier-lunaire.fr/the-moon/";
// Lecture d'un fichier HTML
function lit_html($chaine,$isFile) {
// on lit le fichier ou la chaîne
if($isFile) $chaine = @file_get_contents($chaine);
if($chaine) {
return $chaine;
}
}
$html_infos = lit_html($url,true);
$moon_img = "not found";
$moon_img1 = preg_split("/<div class=\"moon\">/",$html_infos);
$moon_img2 = preg_split("/<\/div>/",$moon_img1[1]);
$moon_img3 = $moon_img2[0];
$moon_img4 = preg_split("/\"/",$moon_img3);
$moon_img5 = preg_split("/\"/",$moon_img4[1]);
$moon_img = $moon_img5[0];
$moon_state = "unknown";
$moon_pourcent = "-1";
// Lune croissante
if ( preg_match("/moon_wax/",$moon_img) ) {
$moon_state = "waxing";
$moon_pourcent1 = preg_split("/moon_wax_/",$moon_img);
$moon_pourcent2 = preg_split("/.png/",$moon_pourcent1[1]);
$moon_pourcent = $moon_pourcent2[0];
}
// Lune décroissante
if ( preg_match("/moon_wan/",$moon_img) ) {
$moon_state = "waning";
$moon_pourcent1 = preg_split("/moon_wan_/",$moon_img);
$moon_pourcent2 = preg_split("/.png/",$moon_pourcent1[1]);
$moon_pourcent = $moon_pourcent2[0];
}
$moon_phase = -1;
// Lune croissante
if ( $moon_state == "waxing" ) {
// Lune nouvelle
if ( $moon_pourcent >=0 and $moon_pourcent <10 ) {
$moon_phase = 1;
}
// Lune premier croissant
if ( $moon_pourcent >=10 and $moon_pourcent <40 ) {
$moon_phase = 8;
}
// Lune premier quartier
if ( $moon_pourcent >=40 and $moon_pourcent <60 ) {
$moon_phase = 7;
}
// Lune gibbeuse montante
if ( $moon_pourcent >=60 and $moon_pourcent <90 ) {
$moon_phase = 6;
}
// Lune pleine
if ( $moon_pourcent >=90 and $moon_pourcent <=100 ) {
$moon_phase = 5;
}
}
// Lune décroissante
if ( $moon_state == "waning" ) {
// Lune nouvelle
if ( $moon_pourcent >=0 and $moon_pourcent <10 ) {
$moon_phase = 1;
}
// Lune dernier croissant
if ( $moon_pourcent >=10 and $moon_pourcent <40 ) {
$moon_phase = 2;
}
// Lune dernier quartier
if ( $moon_pourcent >=40 and $moon_pourcent <60 ) {
$moon_phase = 3;
}
// Lune gibbeuse descendante
if ( $moon_pourcent >=60 and $moon_pourcent <90 ) {
$moon_phase = 4;
}
// Lune pleine
if ( $moon_pourcent >=90 and $moon_pourcent <=100 ) {
$moon_phase = 1;
}
}
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>";
echo "<moon>";
echo " <phase>".$moon_phase."</phase>";
echo " <state>".$moon_state."</state>";
echo " <pourcent>".$moon_pourcent."</pourcent>";
echo " <image>".$moon_img."</image>";
echo "</moon>";
?>
Ce script PHP est a héberger sur votre serveur Web (NAS, etc..) et génère lors de son appel une page Web de type XML contenant :
- Code : Tout sélectionner
<?xml version="1.0" encoding="ISO-8859-1" ?>
<moon>
<phase>2</phase>
<state>waning</state>
<pourcent>22</pourcent>
<image>http://www.calendrier-lunaire.fr/moon/moon_wan_22.png</image>
</moon>
Lune Phase :
Autre type de périphérique = HTTP - Capteur
Type de données : "Liste de valeurs"
URL de la requête : "http://votreserveurweb/script.php",
Chemin XPATH : "/moon/phase"
-1 = Indéterminée
1 = Nouvelle Lune
2 = Dernier Croissant
3 = Dernier Quartier
4 = Lune Gibbeuse descendante
5 = Plein Lune
6 = Lune Gibbeuse montante
7 = Premier Quartier
8 = Premier Croissant
Lune Etat :
Autre type de périphérique = HTTP - Capteur
Type de données = "Liste de valeurs"
URL de la requête = "http://votreserveurweb/script.php",
Chemin XPATH = "/moon/state"
unknown = Indéterminée
waning = Lune Décroissante
waxing = Lune Croissante
Lune Pourcentage :
Autre type de périphérique = HTTP - Capteur
Unité = %
Type de données = "Nombre décimal"
URL de la requête = "http://votreserveurweb/script.php",
Chemin XPATH = "/moon/pourcent"
Lune URL Image :
Elle est contenue dans le Chemin XPATH = "/moon/image"
de la forme http://www.calendrier-lunaire.fr/moon/moon_wan_22.png
Lune exemples d'Icônes :
http://www.deviantart.com/art/Presto-s-Moon-Phases-53625689
http://www.deviantart.com/morelikethis/artists/187306753?view_mode=2/#/art/plain-moon-phase-icons-212524125?hf=1