karasu / meteocat

Meteocat homeassistant component
GNU General Public License v3.0
8 stars 1 forks source link

Functional alternative to this code #2

Open asdrolf opened 3 years ago

asdrolf commented 3 years ago

Hi if someone arrived here searching how to integrate meteocat info on HA. I'm working on a solution.

Use this in a PHP file and upload it to your webserver, change this url "https://www.meteo.cat/prediccio/municipal/000000000" for the url of your city. and http://serv/meteo.php for your php file

Then you can put a iframe component on HA to show this webpage.

And/or use scrape to scrape info out of it (https://try.jsoup.org/)

i m still working on it...if someone is interested and want to work together let me know! hope it helps!

<html lang="ca">
    <head>
 <meta charset="UTF-8" />
        <title>ElTemps</title>
<link rel="stylesheet" href="https://static-m.meteo.cat/assets-w3/stylesheets/style.min.css"/>
<link rel="stylesheet" href="https://static-m.meteo.cat/assets-w3/stylesheets/print.min.css" media="print"/>
<script src="https://static-m.meteo.cat/assets-w3/javascripts/script.vendors.min.js"></script>
<script src="https://static-m.meteo.cat/assets-w3/javascripts/script.min.js"></script>
<link href="https://fonts.googleapis.com/css2?family=Open+Sans&family=Roboto&display=swap" rel="stylesheet">

    </head>
 <body>
<main class="municipal" style="margin: 10 !important;">
<section class="layout" style="width: 100% !important;">
<?

$page = file_get_contents('https://www.meteo.cat/prediccio/municipal/000000000');
@$doc = new DOMDocument();
$doc2 = new DOMDocument();
@$doc->loadHTML($page);   

$xpath = new DomXPath($doc);

$nodeList = $xpath->query("//div[@class='l-box']");

$doc2->appendChild($doc2->importNode($nodeList->item(3),true));
$doc2->appendChild($doc2->importNode($nodeList->item(4),true));

$innerHTML.=trim($doc2->saveHTML());

echo $innerHTML;

?>
</section>
</main>
 </body>
</html>
marcgarciamarti commented 3 years ago

Hi! I'm interested in accessing meteocat data from within HA. I'm really bad at coding though. Is there any chance you could try to wrap this and make it available in HACS? I would be extremely interested in actioning on the information of a specific weather station like https://www.meteo.cat/observacions/xema/dades?codi=XV I guess that for making this possible, it would be needed to define sensors for every metric published. Does this sound feasible at all? Thank you in advance!!

marcgarciamarti commented 2 years ago

Hi if someone arrived here searching how to integrate meteocat info on HA. I'm working on a solution.

Use this in a PHP file and upload it to your webserver, change this url "https://www.meteo.cat/prediccio/municipal/000000000" for the url of your city. and http://serv/meteo.php for your php file

Then you can put a iframe component on HA to show this webpage.

And/or use scrape to scrape info out of it (https://try.jsoup.org/)

i m still working on it...if someone is interested and want to work together let me know! hope it helps!

  • platform: scrape name: Dia1_dataavui resource: http://serv/meteo.php select: "div#tabs-dia1 " attribute: data-tab

    • platform: scrape name: Dia1_hora resource: http://serv/meteo.php select: "div#tabs-dia1 table tr:nth-of-type(1) td:nth-of-type(1)"
    • platform: scrape name: Dia1_tempstxt resource: http://serv/meteo.php select: "div#tabs-dia1 table tr:nth-of-type(2) td:nth-of-type(1)" attribute: alt
    • platform: scrape name: Dia1_tempsimg resource: http://serv/meteo.php select: "div#tabs-dia1 table tr:nth-of-type(2) td:nth-of-type(1)" attribute: src
    • platform: scrape name: Dia1_temp resource: http://serv/meteo.php select: "div#tabs-dia1 table tr:nth-of-type(3) td:nth-of-type(1)" unit_of_measurement: 'ºC'
    • platform: scrape name: Dia1_precip resource: http://serv/meteo.php select: "div#tabs-dia1 table tr:nth-of-type(4) td:nth-of-type(1)" unit_of_measurement: 'mm'
    • platform: scrape name: Dia1_vent resource: http://serv/meteo.php select: "div#tabs-dia1 table tr:nth-of-type(5) td:nth-of-type(1)" unit_of_measurement: 'Km/h'
    • platform: scrape name: Dia1_hora2 resource: http://serv/meteo.php select: "div#tabs-dia1 table tr:nth-of-type(1) td:nth-of-type(2)"
    • platform: scrape name: Dia1_tempstxt2 resource: http://serv/meteo.php select: "div#tabs-dia1 table tr:nth-of-type(2) td:nth-of-type(2)" attribute: alt
    • platform: scrape name: Dia1_tempsimg2 resource: http://serv/meteo.php select: "div#tabs-dia1 table tr:nth-of-type(2) td:nth-of-type(2)" attribute: src
    • platform: scrape name: Dia1_temp2 resource: http://serv/meteo.php select: "div#tabs-dia1 table tr:nth-of-type(3) td:nth-of-type(2)" unit_of_measurement: 'ºC'
    • platform: scrape name: Dia1_precip2 resource: http://serv/meteo.php select: "div#tabs-dia1 table tr:nth-of-type(4) td:nth-of-type(2)" unit_of_measurement: 'mm'
    • platform: scrape name: Dia1_vent2 resource: http://serv/meteo.php select: "div#tabs-dia1 table tr:nth-of-type(5) td:nth-of-type(2)" unit_of_measurement: 'Km/h'
<html lang="ca">
    <head>
 <meta charset="UTF-8" />
        <title>ElTemps</title>
<link rel="stylesheet" href="https://static-m.meteo.cat/assets-w3/stylesheets/style.min.css"/>
<link rel="stylesheet" href="https://static-m.meteo.cat/assets-w3/stylesheets/print.min.css" media="print"/>
<script src="https://static-m.meteo.cat/assets-w3/javascripts/script.vendors.min.js"></script>
<script src="https://static-m.meteo.cat/assets-w3/javascripts/script.min.js"></script>
<link href="https://fonts.googleapis.com/css2?family=Open+Sans&family=Roboto&display=swap" rel="stylesheet">

    </head>
 <body>
<main class="municipal" style="margin: 10 !important;">
<section class="layout" style="width: 100% !important;">
<?

$page = file_get_contents('https://www.meteo.cat/prediccio/municipal/000000000');
@$doc = new DOMDocument();
$doc2 = new DOMDocument();
@$doc->loadHTML($page);   

$xpath = new DomXPath($doc);

$nodeList = $xpath->query("//div[@class='l-box']");

$doc2->appendChild($doc2->importNode($nodeList->item(3),true));
$doc2->appendChild($doc2->importNode($nodeList->item(4),true));

$innerHTML.=trim($doc2->saveHTML());

echo $innerHTML;

?>
</section>
</main>
 </body>
</html>

Hi @asdrolf did you ever manage to pull this off?