2020-02-04 19:24:42 +03:00
|
|
|
<?php
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-02-04 19:24:42 +03:00
|
|
|
class AtmoOccitanieBridge extends BridgeAbstract
|
|
|
|
{
|
|
|
|
const NAME = 'Atmo Occitanie';
|
|
|
|
const URI = 'https://www.atmo-occitanie.org/';
|
|
|
|
const DESCRIPTION = 'Fetches the latest air polution of cities in Occitanie from Atmo';
|
|
|
|
const MAINTAINER = 'floviolleau';
|
|
|
|
const PARAMETERS = [[
|
|
|
|
'city' => [
|
|
|
|
'name' => 'Ville',
|
2022-03-24 13:59:34 +03:00
|
|
|
'required' => true,
|
|
|
|
'exampleValue' => 'cahors'
|
2022-07-01 16:10:30 +03:00
|
|
|
]
|
2020-02-04 19:24:42 +03:00
|
|
|
]];
|
|
|
|
const CACHE_TIMEOUT = 7200;
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-02-04 19:24:42 +03:00
|
|
|
public function collectData()
|
|
|
|
{
|
|
|
|
$uri = self::URI . $this->getInput('city');
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-01-02 12:36:09 +03:00
|
|
|
$html = getSimpleHTMLDOM($uri);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-02-04 19:24:42 +03:00
|
|
|
$generalMessage = $html->find('.landing-ville .city-banner .iqa-avertissement', 0)->innertext;
|
|
|
|
$recommendationsDom = $html->find('.landing-ville .recommandations', 0);
|
|
|
|
$recommendationsItemDom = $recommendationsDom->find('.recommandation-item .label');
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-02-04 19:24:42 +03:00
|
|
|
$recommendationsMessage = '';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-02-04 19:24:42 +03:00
|
|
|
$i = 0;
|
|
|
|
$len = count($recommendationsItemDom);
|
|
|
|
foreach ($recommendationsItemDom as $key => $value) {
|
|
|
|
if ($i == 0) {
|
|
|
|
$recommendationsMessage .= trim($value->innertext) . '.';
|
|
|
|
} else {
|
|
|
|
$recommendationsMessage .= ' ' . trim($value->innertext) . '.';
|
|
|
|
}
|
|
|
|
$i++;
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-02-04 19:24:42 +03:00
|
|
|
$lastRecommendationsDom = $recommendationsDom->find('.col-md-6', -1);
|
|
|
|
$informationHeaderMessage = $lastRecommendationsDom->find('.heading', 0)->innertext;
|
|
|
|
$indice = $lastRecommendationsDom->find('.current-indice .indice div', 0)->innertext;
|
|
|
|
$informationDescriptionMessage = $lastRecommendationsDom->find('.current-indice .description p', 0)->innertext;
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-02-04 19:24:42 +03:00
|
|
|
$message = "$generalMessage L'indice est de $indice/10. $informationDescriptionMessage. $recommendationsMessage";
|
|
|
|
$city = $this->getInput('city');
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-02-04 19:24:42 +03:00
|
|
|
$item['uri'] = $uri;
|
|
|
|
$today = date('d/m/Y');
|
|
|
|
$item['title'] = "Bulletin de l'air du $today pour la ville : $city.";
|
|
|
|
//$item['title'] .= ' Retrouvez plus d\'informations en allant sur atmo-occitanie.org #QualiteAir. ' . $message;
|
|
|
|
$item['title'] .= ' #QualiteAir. ' . $message;
|
|
|
|
$item['author'] = 'floviolleau';
|
|
|
|
$item['content'] = $message;
|
|
|
|
$item['uid'] = hash('sha256', $item['title']);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-02-04 19:24:42 +03:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|