]> Raphaël G. Git Repositories - airbundle/blobdiff - Command/WeatherCommand.php
Inherit captcha
[airbundle] / Command / WeatherCommand.php
index ee339810c65f721e0ee5b302e5f360153441dc24..b499390e0912b2f135a08acdf07530b1bb75f588 100644 (file)
@@ -1,9 +1,19 @@
-<?php
+<?php declare(strict_types=1);
+
+/*
+ * This file is part of the Rapsys AirBundle package.
+ *
+ * (c) Raphaël Gertz <symfony@rapsys.eu>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
 
 namespace Rapsys\AirBundle\Command;
 
 use Doctrine\Bundle\DoctrineBundle\Command\DoctrineCommand;
 use Doctrine\Persistence\ManagerRegistry;
 
 namespace Rapsys\AirBundle\Command;
 
 use Doctrine\Bundle\DoctrineBundle\Command\DoctrineCommand;
 use Doctrine\Persistence\ManagerRegistry;
+
 use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Output\OutputInterface;
 use Symfony\Component\Filesystem\Exception\IOException;
 use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Output\OutputInterface;
 use Symfony\Component\Filesystem\Exception\IOException;
@@ -40,6 +50,7 @@ class WeatherCommand extends DoctrineCommand {
                        75006 => 'https://www.accuweather.com/fr/fr/paris-06-luxembourg/75006/hourly-weather-forecast/179147_pc?day=',
                        75007 => 'https://www.accuweather.com/en/fr/paris-07-palais-bourbon/75007/hourly-weather-forecast/179148_pc?day=',
                        75009 => 'https://www.accuweather.com/en/fr/paris-09-opera/75009/hourly-weather-forecast/179150_pc?day=',
                        75006 => 'https://www.accuweather.com/fr/fr/paris-06-luxembourg/75006/hourly-weather-forecast/179147_pc?day=',
                        75007 => 'https://www.accuweather.com/en/fr/paris-07-palais-bourbon/75007/hourly-weather-forecast/179148_pc?day=',
                        75009 => 'https://www.accuweather.com/en/fr/paris-09-opera/75009/hourly-weather-forecast/179150_pc?day=',
+                       75010 => 'https://www.accuweather.com/en/fr/paris-10-entrepot/75010/hourly-weather-forecast/179151_pc?day=',
                        75012 => 'https://www.accuweather.com/en/fr/paris-12-reuilly/75012/hourly-weather-forecast/179153_pc?day=',
                        75013 => 'https://www.accuweather.com/en/fr/paris-13-gobelins/75013/hourly-weather-forecast/179154_pc?day=',
                        75015 => 'https://www.accuweather.com/en/fr/paris-15-vaugirard/75015/hourly-weather-forecast/179156_pc?day=',
                        75012 => 'https://www.accuweather.com/en/fr/paris-12-reuilly/75012/hourly-weather-forecast/179153_pc?day=',
                        75013 => 'https://www.accuweather.com/en/fr/paris-13-gobelins/75013/hourly-weather-forecast/179154_pc?day=',
                        75015 => 'https://www.accuweather.com/en/fr/paris-15-vaugirard/75015/hourly-weather-forecast/179156_pc?day=',
@@ -54,6 +65,7 @@ class WeatherCommand extends DoctrineCommand {
                        75006 => 'https://www.accuweather.com/fr/fr/paris-06-luxembourg/75006/daily-weather-forecast/179147_pc',
                        75007 => 'https://www.accuweather.com/en/fr/paris-07-palais-bourbon/75007/daily-weather-forecast/179148_pc',
                        75009 => 'https://www.accuweather.com/en/fr/paris-09-opera/75009/daily-weather-forecast/179150_pc',
                        75006 => 'https://www.accuweather.com/fr/fr/paris-06-luxembourg/75006/daily-weather-forecast/179147_pc',
                        75007 => 'https://www.accuweather.com/en/fr/paris-07-palais-bourbon/75007/daily-weather-forecast/179148_pc',
                        75009 => 'https://www.accuweather.com/en/fr/paris-09-opera/75009/daily-weather-forecast/179150_pc',
+                       75010 => 'https://www.accuweather.com/en/fr/paris-10-entrepot/75010/daily-weather-forecast/179151_pc',
                        75012 => 'https://www.accuweather.com/en/fr/paris-12-reuilly/75012/daily-weather-forecast/179153_pc',
                        75013 => 'https://www.accuweather.com/en/fr/paris-13-gobelins/75013/daily-weather-forecast/179154_pc',
                        75015 => 'https://www.accuweather.com/en/fr/paris-15-vaugirard/75015/daily-weather-forecast/179156_pc',
                        75012 => 'https://www.accuweather.com/en/fr/paris-12-reuilly/75012/daily-weather-forecast/179153_pc',
                        75013 => 'https://www.accuweather.com/en/fr/paris-13-gobelins/75013/daily-weather-forecast/179154_pc',
                        75015 => 'https://www.accuweather.com/en/fr/paris-15-vaugirard/75015/daily-weather-forecast/179156_pc',
@@ -97,7 +109,7 @@ class WeatherCommand extends DoctrineCommand {
        }
 
        ///Process the attribution
        }
 
        ///Process the attribution
-       protected function execute(InputInterface $input, OutputInterface $output) {
+       protected function execute(InputInterface $input, OutputInterface $output): int {
                //Kernel object
                $kernel = $this->getApplication()->getKernel();
 
                //Kernel object
                $kernel = $this->getApplication()->getKernel();
 
@@ -246,21 +258,20 @@ class WeatherCommand extends DoctrineCommand {
 
                                //Load simplexml
                                //XXX: trash all xmlns= broken tags
 
                                //Load simplexml
                                //XXX: trash all xmlns= broken tags
-                               $sx = new \SimpleXMLElement(str_replace(['xmlns=', 'xlink:href='], ['xns=', 'href='], $tidy));
+                               $sx = new \SimpleXMLElement(str_replace(['xmlns=', 'xlink:href='], ['xns=', 'href='], (string)$tidy));
 
                                //Process daily
                                if ($day == 'daily') {
                                        //Iterate on each link containing data
                                        foreach($sx->xpath('//a[contains(@class,"daily-forecast-card")]') as $node) {
                                                //Get date
 
                                //Process daily
                                if ($day == 'daily') {
                                        //Iterate on each link containing data
                                        foreach($sx->xpath('//a[contains(@class,"daily-forecast-card")]') as $node) {
                                                //Get date
-                                               $dsm = trim($node->div[0]->h2[0]->span[1]);
+                                               $dsm = trim((string)$node->div[0]->h2[0]->span[1]);
 
                                                //Get temperature
 
                                                //Get temperature
-                                               $temperature = str_replace('°', '', $node->div[0]->div[0]->span[0]);
+                                               $temperature = str_replace('°', '', (string)$node->div[0]->div[0]->span[0]);
 
                                                //Get rainrisk
 
                                                //Get rainrisk
-                                               #$rainrisk = str_replace('%', '', trim($node->div[2]))/100;
-                                               $rainrisk = trim(str_replace('%', '', $node->div[1]))/100;
+                                               $rainrisk = trim(str_replace('%', '', (string)$node->div[1]))/100;
 
                                                //Store data
                                                $data[$zipcode][$dsm]['daily'] = [
 
                                                //Store data
                                                $data[$zipcode][$dsm]['daily'] = [
@@ -275,31 +286,30 @@ class WeatherCommand extends DoctrineCommand {
                                        #/html/body/div[1]/div[5]/div[1]/div[1]/div[1]/div[1]/div[1]/div/h2/span[1]
                                        foreach($sx->xpath('//div[@data-shared="false"]') as $node) {
                                                //Get hour
                                        #/html/body/div[1]/div[5]/div[1]/div[1]/div[1]/div[1]/div[1]/div/h2/span[1]
                                        foreach($sx->xpath('//div[@data-shared="false"]') as $node) {
                                                //Get hour
-                                               $hour = trim(str_replace(' h', '', $node->div[0]->div[0]->div[0]->div[0]->div[0]->h2[0]));
+                                               $hour = trim(str_replace(' h', '', (string)$node->div[0]->div[0]->div[0]->div[0]->div[0]->h2[0]));
 
                                                //Compute dsm from day (1=d,2=d+1,3=d+2)
                                                $dsm = (new \DateTime('+'.($day - 1).' day'))->format('d/m');
 
                                                //Get temperature
 
                                                //Compute dsm from day (1=d,2=d+1,3=d+2)
                                                $dsm = (new \DateTime('+'.($day - 1).' day'))->format('d/m');
 
                                                //Get temperature
-                                               $temperature = str_replace('°', '', $node->div[0]->div[0]->div[0]->div[0]->div[1]);
+                                               $temperature = str_replace('°', '', (string)$node->div[0]->div[0]->div[0]->div[0]->div[1]);
 
                                                //Get realfeel
 
                                                //Get realfeel
-                                               $realfeel = trim(str_replace(['RealFeel®', '°'], '', $node->div[0]->div[0]->div[0]->div[1]->div[0]->div[0]->div[0]));
+                                               $realfeel = trim(str_replace(['RealFeel®', '°'], '', (string)$node->div[0]->div[0]->div[0]->div[1]->div[0]->div[0]->div[0]));
 
                                                //Get rainrisk
 
                                                //Get rainrisk
-                                               $rainrisk = floatval(str_replace('%', '', trim($node->div[0]->div[0]->div[0]->div[2]->div[0]))/100);
+                                               $rainrisk = floatval(str_replace('%', '', trim((string)$node->div[0]->div[0]->div[0]->div[2]->div[0]))/100);
 
                                                //Set rainfall to 0 (mm)
                                                $rainfall = 0;
 
                                                //Iterate on each entry
                                                //TODO: wind and other infos are present in $node->div[1]->div[0]->div[1]->div[0]->p
 
                                                //Set rainfall to 0 (mm)
                                                $rainfall = 0;
 
                                                //Iterate on each entry
                                                //TODO: wind and other infos are present in $node->div[1]->div[0]->div[1]->div[0]->p
-                                               #foreach($node->div[1]->div[0]->div[1]->div[1]->p as $p) {
                                                foreach($node->div[1]->div[0]->div[1]->div[0]->p as $p) {
                                                        //Lookup for rain entry if present
                                                foreach($node->div[1]->div[0]->div[1]->div[0]->p as $p) {
                                                        //Lookup for rain entry if present
-                                                       if (in_array(trim($p), ['Rain', 'Pluie'])) {
+                                                       if (in_array(trim((string)$p), ['Rain', 'Pluie'])) {
                                                                //Get rainfall
                                                                //Get rainfall
-                                                               $rainfall = floatval(str_replace(' mm', '', $p->span[0]));
+                                                               $rainfall = floatval(str_replace(' mm', '', (string)$p->span[0]));
                                                        }
                                                }
 
                                                        }
                                                }
 
@@ -443,7 +453,6 @@ class WeatherCommand extends DoctrineCommand {
                                        //Check if realfeel differ
                                        if ($session->getRealfeel() !== $realfeel) {
                                                //Set average realfeel
                                        //Check if realfeel differ
                                        if ($session->getRealfeel() !== $realfeel) {
                                                //Set average realfeel
-                                               #$meteo['realfeel'] = array_sum($meteo['realfeel'])/count($meteo['realfeel']);
                                                $session->setRealfeel($realfeel);
                                        }
 
                                                $session->setRealfeel($realfeel);
                                        }
 
@@ -468,7 +477,6 @@ class WeatherCommand extends DoctrineCommand {
                                        //Check if temperature differ
                                        if ($session->getTemperature() !== $temperature) {
                                                //Set average temperature
                                        //Check if temperature differ
                                        if ($session->getTemperature() !== $temperature) {
                                                //Set average temperature
-                                               #$meteo['temperature'] = array_sum($meteo['temperature'])/count($meteo['temperature']);
                                                $session->setTemperature($temperature);
                                        }
 
                                                $session->setTemperature($temperature);
                                        }