Addentum

Mon tout premier Script

heure.php

<?php
$heure = date('H') . ":" . date('i') . ":" . date('s');
echo "<heure>" . $heure . "</heure>";
?>

Mon tout premier Plugin

readme_fr.md

Ce plugin vous donnera l'heure sous la forme :

**hh:mm:ss**

*NB: il ne se mettra à l'heure que toutes les minutes, il ne s'agit ici que d'un exemple dans le cadre des mini-didacticiels "Pied à l'Etrier"*

## Installation
Cliquez sur le plugin, puis faites **créer**, puis dans le fenêtre de configuration, indiquez seulement la pièce dans laquelle il doit apparaître.

eedomus_plugin.json

{
"plugin_id": "heure",
"name_fr": "Heure",
"icon": "heure.png",
"version": "1.0",
"creation_date": "2020-01-01",
"modification_date": "2020-01-01",
"author": "eedotrucs",
"description_fr": "heure sous la forme hh:mm:ss",
"description_en": "",
"description_es": "",
"description_it": "",
"description_de": "",
"forum_link": "",

"parameters": [{
      "parameter": "config_info",
      "description": "<b>--------- N\\'oubliez pas ! ---------</b>",
      "xtype": "displayfield",
      "field": "style: 'padding: 3px;', value: 'N\\'oubliez pas d'\\indiquer la pièce<br>sinon votre capteur serait invisible !'"
}],

"scripts": [{
      "name": "heure.php"
}],

"devices": [{
      "device_id": "device_heure",
      "module_id": "51",
      "type": "http",
      "name_fr": "Heure",
      "icon": "heure.png",
      "utilisation_id": "35",
      "parameters":{
            "value_type": "string",
            "ignore_errors": 3,
            "RAW_URL": "http://localhost/script/?exec=heure.php",
            "RAW_XPATH": "//heure",
            "POLLING": "1"
      }
}]
}

Modification du script "Horloge"

horloge.php

<?php
$heure = date('G') . date('i');
$horloge = date('H') . ":" . date('i') . ":" . date('s');
echo "<time>\n";
echo "<heure>" . $heure . "</heure>\n";
echo "<horloge>" . $horloge . "</horloge>\n";
echo "</time>";
?>

Modification du plugin "Horloge"

eedomus_plugin.json

{
"plugin_id": "horloge",
"name_fr": "Horloge",
"icon": "horloge.png",
"version": "1.0",
"creation_date": "2017-11-28",
"modification_date": "2017-11-28",
"author": "Eedomusbox",
"description_fr": "Horloge, permet d'afficher l'heure",
"description_en": "",
"description_es": "",
"description_it": "",
"description_de": "",
"forum_link": "http://forum.eedomus.com/viewtopic.php?f=50&t=6196#p57554",

"parameters": [{
      "parameter": "box_horloge",
      "description": "je veux créer une horloge (hmm) :",
      "xtype": "checkbox",
      "field": "style: 'margin-top: 6px;', checked: true"
      },
            {
      "parameter": "box_heure",
      "description": "je veux créer un affichage de l'heure (hh:mm:ss) :",
      "xtype": "checkbox",
      "field": "style: 'margin-top: 6px;', checked: true"
      }
],
"scripts": [
{
      "name": "horloge.php"
}
],
"devices": [
      {
      "device_id": "horloge",
      "create":"plugin.parameters.box_horloge",
      "module_id": "51",
      "type": "http",
      "name_fr": "Horloge",
      "icon": "horloge.png",
      "utilisation_id": "35",
      "parameters": {
            "value_type": "string",
            "ignore_errors": 3,
            "RAW_URL": "http://localhost/script/?exec=horloge.php",
            "RAW_XPATH": "//heure",
            "POLLING": "1"
            }
      },{
      "device_id": "heure",
      "create":"plugin.parameters.box_heure",
      "module_id": "51",
      "type": "http",
      "name_fr": "Heure",
      "icon": "heure.png",
      "utilisation_id": "35",
      "parameters": {
            "value_type": "string",
            "ignore_errors": 3,
            "RAW_URL": "http://localhost/script/?exec=horloge.php",
            "RAW_XPATH": "//horloge",
            "POLLING": "1"
            }
      }
]
}

Script "Horloge" par appel d'une variable

horloge.php

<?php
$format_heure= getArg('format_heure');
$heure = date('G') . date('i');
$horloge = date('H') . ":" . date('i') . ":" . date('s');
echo "<time>\n<heure>";
if ($format_heure == "hh:mm:ss") {echo $horloge;}else{echo $heure;}
echo "</heure>\n</time>";

?>

eedomus_plugin.json

{
"plugin_id": "horloge",
"name_fr": "Horloge",
"icon": "horloge.png",
"version": "1.0",
"creation_date": "2017-11-28",
"modification_date": "2017-11-28",
"author": "Eedomusbox",
"description_fr": "Horloge, permet d'afficher l'heure",
"description_en": "",
"description_es": "",
"description_it": "",
"description_de": "",
"forum_link": "http://forum.eedomus.com/viewtopic.php?f=50&t=6196#p57554",

"parameters": [{
      "parameter": "box_horloge",
      "description": "je veux créer une horloge (hmm) :",
      "xtype": "checkbox",
      "field": "style: 'margin-top: 6px;', checked: true"
      },            {
      "parameter": "box_heure",
      "description": "je veux créer un affichage de l'heure (hh:mm:ss) :",
      "xtype": "checkbox",
      "field": "style: 'margin-top: 6px;', checked: true"
      }
],
"scripts": [
{
      "name": "horloge.php"
}
],
"devices": [
      {
      "device_id": "horloge",
      "create":"plugin.parameters.box_horloge",
      "module_id": "51",
      "type": "http",
      "name_fr": "Horloge",
      "icon": "horloge.png",
      "utilisation_id": "35",
      "parameters": {
            "value_type": "string",
            "ignore_errors": 3,
            "RAW_URL": "http://localhost/script/?exec=heure.php&format_heure=[VAR1]",
            "RAW_XPATH": "//heure",
            "POLLING": "1"
            }
      },{
      "device_id": "heure",
      "create":"plugin.parameters.box_heure",
      "module_id": "51",
      "type": "http",
      "name_fr": "Heure",
      "icon": "heure.png",
      "utilisation_id": "35",
      "parameters": {
            "VAR1" : "hh:mm:ss",
            "value_type": "string",
            "ignore_errors": 3,
            "RAW_URL": "http://localhost/script/?exec=heure.php&format_heure=[VAR1]",
            "RAW_XPATH": "//heure",
            "POLLING": "1"
            }
      }
]
}

Micro-Météo : France

<?php
$url = "https://meteo.orange.fr/";
$url = httpQuery($url,'GET');
$url = preg_replace('#.*<div class="vigilance-bulletin-status"><strong>|</strong></div>.*#s',"",$url);
$url = preg_replace("#.*</strong><br /><strong>#","",$url);
$url = "<bulletin>" . $url . "</bulletin>";
echo $url;

?>

Micro-Météo : France (condensé)

<?php
$url = "https://meteo.orange.fr/";
$url = httpQuery($url,'GET');
$url = preg_replace('#.*<div class="vigilance-bulletin-status"><strong>|</strong></div>.*#s',"",$url);
$url = preg_replace("#.*</strong><br /><strong>#","",$url);

$url = str_replace("même type de temps,","", $url);
$o = array(".","nord","sud","ouest","est","Eival",", et","encore"," et ","des pyrénées","des alpes");
$r = array(",","N","S","O","E","estival",",","",", ","pyrénéen","alpin");
$url = str_replace($o, $r, strtolower($url));
$url = preg_replace ("#([NSEO])-([NSEO])-?([EO])?#","$1$2$3",trim($url));
$url = preg_replace("/,$/",".",trim($url));
$url = strtoupper($url[0]).substr($url, 1);

$url = "<bulletin>" . $url . "</bulletin>";
echo $url;
?>

Extractions

Micro-Météo : France (extrait)

<?php
$url = httpQuery ("http://meteo.orange.fr",'GET');

preg_match_all ('#<div class="vigilance-bulletin-status">\s*<strong>(.*)</strong>\s*<br>\s*<strong>(.*)\s*</strong>\s*</div>#',$url,$matches);
$url = $matches[2][0];


$url = "<bulletin>" . $url . "</bulletin>";
echo $url;
?>

Exercice Virtuel : foreach

<?php
function httpQuery($url) {
// coller dans l'espace libre ci dessous le code source de la page HTML appellée
$return=<<<'pageHTML'

code avant

<div class="vigilance-bulletin-status">
<strong>Aujourdhui</strong></div>

code quelconque

<div class="vigilance-bulletin-données">
matin<strong>Orageux.</strong></div

<div class="vigilance-bulletin-données">
midi<strong>Moins orageux.</strong></div

<div class="vigilance-bulletin-données">
soir<strong>Les orages se terminent.</strong></div

code quelconque

<div class="vigilance-bulletin-status">
<strong>Demain</strong></div>

code quelconque

<div class="vigilance-bulletin-données">
matin<strong>Beau.</strong></div

<div class="vigilance-bulletin-données">
midi<strong>Grand soleil.</strong></div

code après


pageHTML;
return $return;
}

// =================script=================
$url = "https://meteo.orange.fr/";
$url = httpQuery($url,'GET');
preg_match_all ('#<div
class="vigilance-bulletin-status">\s*<strong>(.*)</strong></div>|<div class="vigilance-bulletin-données">\s*(.*)<strong>(.*)</strong></div#',$url,$matches);

$xml = "<meteo>\n"; // initialisation du xml avec la balise globale
$sbalise = NULL; // définit la variable, ici avec une valeur nulle

foreach($matches[3] as $index => $donnée) {

      if ($matches[1][$index] != '') {
            if ($sbalise != NULL) {$xml .= "</" . $sbalise . ">\n";}
            $sbalise = $matches[1][$index];
            $xml .= "<" . $sbalise . ">\n";
      }elseif ($donnée != ''){
            $xml .= "<" . $matches[2][$index] . ">" . $donnée . "</" . $matches[2][$index] . ">\n";
      }
      }

$xml .= "</" . $sbalise . ">\n"; // fermeture dernière super balise
$xml .= "</meteo>"; // fermeture balise globale

echo $xml;


?>

Micro-Météo : Réunion

<?php
$url = "http://www.meteofrance.re/previsions-meteo-reunion/bulletin";
$url = httpQuery($url,'GET');
preg_match_all('#<div class="mod-body">\s*<div class="article-row">\s*<h2>.*</h2>\s*<p class="p-style-2" style="clear: both;"><br/><br/>(.*)<br/><br/><br/>#',$url,$matches);
$url = strtolower($matches[1][0]);
$url = "<bulletin>" . $url . "</bulletin>";
echo $url;

?>

Bonus : Script Micro-Météo France, Belgique & Réunion

NB: les icônes des cartes météo correspondantes se trouvent dans la liste d'icônes "communauté".
<?php

// http://localhost/script/?exec=bulletin.php&zone=[VAR1]
// VAR: run, be et fr par défaut - //bulletin


$zone= getArg('zone');

if ($zone == "run") {

      $url = "http://www.meteofrance.re/previsions-meteo-reunion/bulletin";
      $url = httpQuery($url,'GET');

      preg_match_all('#<div class="mod-body">\s*<div class="article-row">\s*<h2>.*</h2>\s*<p class="p-style-2" style="clear: both;">(?:<br/>)+(.*?)(?:<br/>)+#',$url,$matches);
      $url = strtolower($matches[1][0]);

} elseif ($zone == "be") {

      $url = "https://www.meteo.be/fr/belgique";
      $url = httpQuery($url,'GET');

      preg_match_all('~; float: left; vertical-align: middle;;"></div>(.*?)</div><~',$url,$matches);
      $url = strtolower($matches[1][0]);

} else {
      
      $url = "http://www.meteofrance.com";
      $url = httpQuery($url,'GET');

      preg_match_all('~class="teaser_article teaser_article_1" title="(.*?)">.*<figure>~s',$url,$matches);
      $url = strtolower($matches[1][0]);
      
}

      $url=utf8_decode($url);

// supprime

      $p = array("même type de temps,","encore","du département","que les jours précédents","..");
      $s = array("","","","","");

// change

      $o = array(".","nord","sud","ouest","est",", et","encore"," et ","des pyrénées","des alpes","« orages »");
      $r = array(",","N","S","O","E",",","",", ","pyrénéen","alpin","orages");

            $o = array_merge($p,$o);
            $r = array_merge($s,$r);

// rétablit

      $p = array("Eival","rEe","E étendue");
      $s = array("estival","reste","est étendue");

            $o = array_merge($o,$p);
            $r = array_merge($r,$s);

      $url = str_replace($o, $r, $url);

// contracte rdv
      $url = preg_replace ("#([NSEO])-([NSEO])-?([EO])?#","$1$2$3",trim($url));

      $url = preg_replace ("/,$/", ".", $url);
      $url = strtoupper($url[0]) . substr($url, 1);

$url = "<bulletin>" . $url . "</bulletin>";
echo $url;

?>