Esempio n. 1
0
 /**
  * Récupere les prévision de T°C de l'eau depuis www.meteocity.com sur les 7 prochains joursS
  */
 static function getTempWater($tempWaterInfoURL, $output)
 {
     // $tempWaterInfoURL: http://www.meteocity.com/france/plage/dieppe_p76217/
     // ajax pour avoir les infos: http://www.meteocity.com/ajax/Beach/ajaxChangeBeachView/?date=20151203+&citId=76217&modificateur=1
     $ajaxUrlType = TempWaterGetData::buildMeteocityAjaxURL($tempWaterInfoURL);
     // ajaxURL avec "__date__" à remplacer par un truc du type 20151203
     //$regExGetTempWater = '#([0-9]+)°C#';
     $regExGetTempWater = '#([0-9]+)#';
     $client = new Client();
     $prevTempWater = array();
     $day = new \DateTime("now");
     // attention dû à une erreure coté meteocity, il faut mettre 20151128 pour avoir les infos du 29/11/2015 ...
     $inter1Day = new \DateInterval('P01D');
     $inter1Day->invert = 1;
     $day->add($inter1Day);
     // enlever un jour
     $inter1Day->invert = 0;
     for ($numJour = 0; $numJour <= 5; $numJour++) {
         $ajaxUrl = str_replace("__date__", $day->format('Ymd'), $ajaxUrlType);
         $day->add($inter1Day);
         // ajout d'un jour
         $output->writeln('<info>url : ' . $ajaxUrl . '</info>');
         $crawler = $client->request('GET', $ajaxUrl);
         /*
         <div class="data-temp-eau">
             <div class="title"><h2>Température de l'eau</h2></div>
             <div class="data-number"><span class="icon"></span> 12°C</div>
         </div>
         */
         $divWater = $crawler->filter(".data-temp-eau");
         // get <div class="data-temp-eau" ...>
         $divTempsWater = $divWater->filter(".data-number");
         // and <div class="data-number" ...>
         preg_match($regExGetTempWater, $divTempsWater->text(), $tempWater);
         $prevTempWater[$numJour] = $tempWater[1];
         $output->writeln('<info>temperature de l eau pour le ' . $day->format('d/m/Y') . ': ' . $tempWater[1] . '</info>');
     }
     return $prevTempWater;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $em = $this->getContainer()->get('doctrine.orm.entity_manager');
     // récupere tous les spots
     $listSpot = $em->getRepository('LaPoizWindBundle:Spot')->findAll();
     foreach ($listSpot as $spot) {
         $output->writeln('<info>Note du Spot ' . $spot->getNom() . ' - </info>');
         // On efface les vielles notes (avant aujourd'hui)
         ManageNote::deleteOldData($spot, $em);
         list($tabDataNbHoureNav, $tabDataMeteo) = NbHoureNav::createTabNbHoureNav($spot, $em);
         $tabNbHoureNav = NbHoureNav::calculateNbHourNav($tabDataNbHoureNav);
         $output->writeln('<info>           *** Nb Heure nav ***</info>');
         // Save nbHoure on spot
         foreach ($tabNbHoureNav as $keyDate => $tabWebSite) {
             $output->writeln('<info>' . $keyDate . ': ');
             $nbHoureNavCalc = 0;
             $nbSiteCalc = 0;
             foreach ($tabWebSite as $keyWebSite => $nbHoureNav) {
                 $output->writeln('<info>    ' . $keyWebSite . ' : ' . $nbHoureNav . '</info> ');
                 $noteDates = ManageNote::getNotesDate($spot, \DateTime::createFromFormat('Y-m-d', $keyDate), $em);
                 $nbHoureNavObj = ManageNote::getNbHoureNav($noteDates, $keyWebSite, $em);
                 $nbHoureNavObj->setNbHoure($nbHoureNav);
                 $em->persist($nbHoureNavObj);
                 $em->persist($noteDates);
                 if ($nbHoureNav > 0) {
                     $nbSiteCalc++;
                     $nbHoureNavCalc += $nbHoureNav;
                 }
             }
             if ($nbSiteCalc > 0) {
                 $output->writeln('<info>    ' . $keyDate . ' : ' . $nbHoureNavCalc . ' / ' . $nbSiteCalc . ' = ' . $nbHoureNavCalc / $nbSiteCalc . '</info> ');
                 $noteDates->setNbHoureNavCalc($nbHoureNavCalc / $nbSiteCalc);
                 $em->persist($noteDates);
             }
         }
         $output->writeln('<info>           *** Meteo ***</info>');
         // Save meteo
         $tabMeteo = NbHoureMeteo::calculateMeteoNav($tabDataMeteo);
         foreach ($tabMeteo as $keyDate => $tabMeteoDay) {
             $output->writeln('<info>   Calcule Meteo of ' . $keyDate . '</info> ');
             $noteDates = ManageNote::getNotesDate($spot, \DateTime::createFromFormat('Y-m-d', $keyDate), $em);
             $noteDates->setTempMax($tabMeteoDay["tempMax"]);
             $noteDates->setTempMin($tabMeteoDay["tempMin"]);
             $noteDates->setMeteoBest($tabMeteoDay["meteoBest"]);
             $noteDates->setMeteoWorst($tabMeteoDay["meteoWorst"]);
             $em->persist($noteDates);
         }
         $output->writeln('<info>           *** T C de l eau ***</info>');
         //********** Température de l'eau **********
         try {
             $tabTempWater = null;
             $tabTempWater = TempWaterGetData::getTempWaterFromSpot($spot, $output);
         } catch (\Exception $e) {
             $output->writeln('<warn>' . $e->getMessage() . '</warn>');
             $output->writeln('<warn> * End Warn * </warn>');
         }
         if ($tabTempWater != null) {
             $currentDay = new \DateTime("now");
             foreach ($tabTempWater as $numJourFromToday => $tempWater) {
                 $noteDates = ManageNote::getNotesDate($spot, clone $currentDay, $em);
                 $noteDates->setTempWater($tempWater);
                 $em->persist($noteDates);
                 $currentDay = date_add($currentDay, new \DateInterval('P1D'));
                 // Jour suivant
             }
         }
         $output->writeln('<info>******************************</info>');
     }
     $em->flush();
 }
 /**
  * @Template()
  * Efface les prévisions de T°C de l'eau
  * http://localhost/Wind/web/app_dev.php/admin/BO/ajax/spot/tempwater/delete/1
  */
 public function tempWaterDeleteAction($id)
 {
     $em = $this->container->get('doctrine.orm.entity_manager');
     $spot = $em->find('LaPoizWindBundle:Spot', $id);
     if (!$spot) {
         return $this->container->get('templating')->renderResponse('LaPoizWindBundle:Default:errorBlock.html.twig', array('errMessage' => "Spot not find !"));
     }
     $tempWaterURL = $spot->getTempWaterURL();
     if (!empty($tempWaterURL)) {
         TempWaterGetData::deleteTempWater($spot, $em, new NullOutput());
     }
     $previsionDate = $em->getRepository('LaPoizWindBundle:PrevisionDate')->findLastPrev(10, $spot);
     return $this->container->get('templating')->renderResponse('LaPoizWindBundle:BackOffice/Spot/Ajax/TempWater:tempWaterSaveResult.html.twig', array('previsionDateDB' => $previsionDateDB, 'spot' => $spot, 'message' => "", 'saveSuccess' => true));
 }