From 1e4778d349341bcc668c381e6de5199203595077 Mon Sep 17 00:00:00 2001 From: Florent VIOLLEAU Date: Sun, 23 Nov 2025 00:50:59 +0100 Subject: [PATCH 1/3] [EdfPricesBridge] Update bridge due to dom changes --- bridges/AtmoOccitanieBridge.php | 3 +-- bridges/EdfPricesBridge.php | 35 +++++++++++++++++++++++++++------ 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/bridges/AtmoOccitanieBridge.php b/bridges/AtmoOccitanieBridge.php index 2388d7e4d26..e74b3f29fd9 100644 --- a/bridges/AtmoOccitanieBridge.php +++ b/bridges/AtmoOccitanieBridge.php @@ -43,13 +43,12 @@ public function collectData() $indice = $lastRecommendationsDom->find('.current-indice .indice div', 0)->innertext; $informationDescriptionMessage = $lastRecommendationsDom->find('.current-indice .description p', 0)->innertext; - $message = "$generalMessage L'indice est de $indice/10. $informationDescriptionMessage. $recommendationsMessage"; + $message = "$generalMessage L'indice est de " . (6 - $indice) . "/6. $informationDescriptionMessage. $recommendationsMessage"; $city = $this->getInput('city'); $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; diff --git a/bridges/EdfPricesBridge.php b/bridges/EdfPricesBridge.php index 8e642c7d607..e72ffe8e598 100644 --- a/bridges/EdfPricesBridge.php +++ b/bridges/EdfPricesBridge.php @@ -39,6 +39,25 @@ class EdfPricesBridge extends BridgeAbstract ]; const CACHE_TIMEOUT = 7200; // 2h + private function removeEmojisAndSpecialSpaces(string $text): string + { + // This regex covers most common emoji ranges in Unicode + $regex = '/[\x{1F600}-\x{1F64F}' . // Emoticons + '\x{1F300}-\x{1F5FF}' . // Misc Symbols and Pictographs + '\x{1F680}-\x{1F6FF}' . // Transport and Map + '\x{1F700}-\x{1F77F}' . // Alchemical Symbols + '\x{1F780}-\x{1F7FF}' . // Geometric Shapes Extended + '\x{1F800}-\x{1F8FF}' . // Supplemental Arrows-C + '\x{1F900}-\x{1F9FF}' . // Supplemental Symbols and Pictographs + '\x{1FA00}-\x{1FA6F}' . // Chess Symbols, Symbols and Pictographs Extended-A + '\x{1FA70}-\x{1FAFF}' . // Symbols and Pictographs Extended-B + '\x{2600}-\x{26FF}' . // Misc symbols + '\x{2700}-\x{27BF}' . // Dingbats + ']+/u'; + + return preg_replace($regex, '', str_replace(' ', '', $text)); + } + /** * @param simple_html_dom $html * @param string $contractUri @@ -47,15 +66,16 @@ class EdfPricesBridge extends BridgeAbstract private function tempo(simple_html_dom $html, string $contractUri, int $power): void { // colors - $ulDom = $html->find('#tarif-de-l-offre-tempo-edf-template-date-now-y', 0)->nextSibling()->nextSibling()->nextSibling(); - $elementsDom = $ulDom->find('li'); + $ulDom = $html->find('#les-tarifs-du-kwh-tempo-pour-les-differentes-couleurs-et-heures-de-la-journee', 0)->nextSibling(); + $elementsDom = $ulDom->children; + if ($elementsDom && count($elementsDom) === 3) { // price per kWh is same for all powers foreach ($elementsDom as $elementDom) { $item = []; $matches = []; - preg_match_all('/Jour (.*) : Heures (.*) : (.*) € \/ Heures (.*) : (.*) €/um', $elementDom->innertext, $matches, PREG_SET_ORDER, 0); + preg_match_all('/Jour (.*) :.*?Heures (.*) : (.*).*?€.*?Heures (.*) : (.*).*?€/um', $this->removeEmojisAndSpecialSpaces($elementDom->plaintext), $matches, PREG_SET_ORDER, 0); // for tempo contract we have 2x3 colors if ($matches && count($matches[0]) === 6) { @@ -74,7 +94,7 @@ private function tempo(simple_html_dom $html, string $contractUri, int $power): } // add subscription power info - $tablePrices = $ulDom->nextSibling()->nextSibling()->nextSibling()->find('.table--responsive', 0); + $tablePrices = $ulDom->nextSibling()->nextSibling(); $this->addSubscriptionPowerInfo($tablePrices, $contractUri, $power, 7); } @@ -186,14 +206,17 @@ private function addSubscriptionPowerInfo(simple_html_dom_node $tablePrices, str { $prices = $tablePrices->find('.table tbody tr'); - // 8 contracts for tempo: 6, 9, 12, 15, 18, 24, 30 and 36 kVA + // 7 contracts for tempo: 6, 9, 12, 15, 18, 30 and 36 kVA // 9 contracts for base: 3, 6, 9, 12, 15, 18, 24, 30 and 36 kVA // 8 contracts for HPHC: 6, 9, 12, 15, 18, 24, 30 and 36 kVA // 5 contracts for EJP: 9, 12, 15, 18 and 36 kVA if ($prices && count($prices) === $numberOfPrices) { $powerFound = false; foreach ($prices as $price) { - $powerText = $price->firstChild()->firstChild()->innertext; + $powerText = trim($price->children(0)->innertext); + if ($price->children(0)->children(0)) { + $powerText = trim($price->children(0)->children(0)->innertext); + } $powerValue = (int)substr($powerText, 0, strpos($powerText, ' kVA')); if ($powerValue !== $power) { From 02b5a2d72d4cdde7974fb8565f894c4ab152b930 Mon Sep 17 00:00:00 2001 From: Florent VIOLLEAU Date: Sun, 23 Nov 2025 00:58:30 +0100 Subject: [PATCH 2/3] [EdfPricesBridge] Lint --- bridges/EdfPricesBridge.php | 38 ++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/bridges/EdfPricesBridge.php b/bridges/EdfPricesBridge.php index e72ffe8e598..917eb59264a 100644 --- a/bridges/EdfPricesBridge.php +++ b/bridges/EdfPricesBridge.php @@ -39,25 +39,25 @@ class EdfPricesBridge extends BridgeAbstract ]; const CACHE_TIMEOUT = 7200; // 2h - private function removeEmojisAndSpecialSpaces(string $text): string - { - // This regex covers most common emoji ranges in Unicode - $regex = '/[\x{1F600}-\x{1F64F}' . // Emoticons - '\x{1F300}-\x{1F5FF}' . // Misc Symbols and Pictographs - '\x{1F680}-\x{1F6FF}' . // Transport and Map - '\x{1F700}-\x{1F77F}' . // Alchemical Symbols - '\x{1F780}-\x{1F7FF}' . // Geometric Shapes Extended - '\x{1F800}-\x{1F8FF}' . // Supplemental Arrows-C - '\x{1F900}-\x{1F9FF}' . // Supplemental Symbols and Pictographs - '\x{1FA00}-\x{1FA6F}' . // Chess Symbols, Symbols and Pictographs Extended-A - '\x{1FA70}-\x{1FAFF}' . // Symbols and Pictographs Extended-B - '\x{2600}-\x{26FF}' . // Misc symbols - '\x{2700}-\x{27BF}' . // Dingbats - ']+/u'; - - return preg_replace($regex, '', str_replace(' ', '', $text)); - } - + private function removeEmojisAndSpecialSpaces(string $text): string + { + // This regex covers most common emoji ranges in Unicode + $regex = '/[\x{1F600}-\x{1F64F}' . // Emoticons + '\x{1F300}-\x{1F5FF}' . // Misc Symbols and Pictographs + '\x{1F680}-\x{1F6FF}' . // Transport and Map + '\x{1F700}-\x{1F77F}' . // Alchemical Symbols + '\x{1F780}-\x{1F7FF}' . // Geometric Shapes Extended + '\x{1F800}-\x{1F8FF}' . // Supplemental Arrows-C + '\x{1F900}-\x{1F9FF}' . // Supplemental Symbols and Pictographs + '\x{1FA00}-\x{1FA6F}' . // Chess Symbols, Symbols and Pictographs Extended-A + '\x{1FA70}-\x{1FAFF}' . // Symbols and Pictographs Extended-B + '\x{2600}-\x{26FF}' . // Misc symbols + '\x{2700}-\x{27BF}' . // Dingbats + ']+/u'; + + return preg_replace($regex, '', str_replace(' ', '', $text)); + } + /** * @param simple_html_dom $html * @param string $contractUri From f1f9d3180094c878574a8794175c693cefae0e3d Mon Sep 17 00:00:00 2001 From: Florent VIOLLEAU Date: Sun, 23 Nov 2025 01:01:48 +0100 Subject: [PATCH 3/3] [EdfPricesBridge] Lint --- bridges/EdfPricesBridge.php | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/bridges/EdfPricesBridge.php b/bridges/EdfPricesBridge.php index 917eb59264a..684801d6afe 100644 --- a/bridges/EdfPricesBridge.php +++ b/bridges/EdfPricesBridge.php @@ -42,17 +42,17 @@ class EdfPricesBridge extends BridgeAbstract private function removeEmojisAndSpecialSpaces(string $text): string { // This regex covers most common emoji ranges in Unicode - $regex = '/[\x{1F600}-\x{1F64F}' . // Emoticons - '\x{1F300}-\x{1F5FF}' . // Misc Symbols and Pictographs - '\x{1F680}-\x{1F6FF}' . // Transport and Map - '\x{1F700}-\x{1F77F}' . // Alchemical Symbols - '\x{1F780}-\x{1F7FF}' . // Geometric Shapes Extended - '\x{1F800}-\x{1F8FF}' . // Supplemental Arrows-C - '\x{1F900}-\x{1F9FF}' . // Supplemental Symbols and Pictographs - '\x{1FA00}-\x{1FA6F}' . // Chess Symbols, Symbols and Pictographs Extended-A - '\x{1FA70}-\x{1FAFF}' . // Symbols and Pictographs Extended-B - '\x{2600}-\x{26FF}' . // Misc symbols - '\x{2700}-\x{27BF}' . // Dingbats + $regex = '/[\x{1F600}-\x{1F64F}' . // Emoticons + '\x{1F300}-\x{1F5FF}' . // Misc Symbols and Pictographs + '\x{1F680}-\x{1F6FF}' . // Transport and Map + '\x{1F700}-\x{1F77F}' . // Alchemical Symbols + '\x{1F780}-\x{1F7FF}' . // Geometric Shapes Extended + '\x{1F800}-\x{1F8FF}' . // Supplemental Arrows-C + '\x{1F900}-\x{1F9FF}' . // Supplemental Symbols and Pictographs + '\x{1FA00}-\x{1FA6F}' . // Chess Symbols, Symbols and Pictographs Extended-A + '\x{1FA70}-\x{1FAFF}' . // Symbols and Pictographs Extended-B + '\x{2600}-\x{26FF}' . // Misc symbols + '\x{2700}-\x{27BF}' . // Dingbats ']+/u'; return preg_replace($regex, '', str_replace(' ', '', $text)); @@ -75,7 +75,13 @@ private function tempo(simple_html_dom $html, string $contractUri, int $power): $item = []; $matches = []; - preg_match_all('/Jour (.*) :.*?Heures (.*) : (.*).*?€.*?Heures (.*) : (.*).*?€/um', $this->removeEmojisAndSpecialSpaces($elementDom->plaintext), $matches, PREG_SET_ORDER, 0); + preg_match_all( + '/Jour (.*) :.*?Heures (.*) : (.*).*?€.*?Heures (.*) : (.*).*?€/um', + $this->removeEmojisAndSpecialSpaces($elementDom->plaintext), + $matches, + PREG_SET_ORDER, + 0 + ); // for tempo contract we have 2x3 colors if ($matches && count($matches[0]) === 6) {