From 803a55071634873303c513e126fc4d41a8f3bb60 Mon Sep 17 00:00:00 2001 From: Florent VIOLLEAU Date: Tue, 19 Dec 2023 02:03:23 +0100 Subject: [PATCH 1/4] [EdfPricesBridge] add new brige --- bridges/EdfPricesBridge.php | 106 ++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 bridges/EdfPricesBridge.php diff --git a/bridges/EdfPricesBridge.php b/bridges/EdfPricesBridge.php new file mode 100644 index 00000000000..985b164f36b --- /dev/null +++ b/bridges/EdfPricesBridge.php @@ -0,0 +1,106 @@ + [ + 'name' => 'Choisir un contrat', + 'type' => 'list', + // we can add later HCHP, EJP, base + 'values' => ['Tempo' => '/energie/edf/tarifs/tempo'], + ] + ] + ]; + const CACHE_TIMEOUT = 7200; // 2h + + /** + * @param simple_html_dom $html + * @param string $contractUri + * @return void + */ + private function tempo(simple_html_dom $html, string $contractUri): void + { + // current color and next + $daysDom = $html->find('#calendrier', 0)?->nextSibling()?->find('.card--ejp'); + if ($daysDom && count($daysDom) === 2) { + foreach ($daysDom as $dayDom) { + $day = trim($dayDom->find('.card__title', 0)->innertext) . '/' . (new \DateTime('now'))->format(('Y')); + $dayColor = $dayDom->find('.card-ejp__icon span', 0)->innertext; + + $text = $day . ' - ' . $dayColor; + $item['uri'] = self::URI . $contractUri; + $item['title'] = $text; + $item['author'] = self::MAINTAINER; + $item['content'] = $text; + $item['uid'] = hash('sha256', $item['title']); + + $this->items[] = $item; + } + } + + // colors + $ulDom = $html->find('#tarif-de-l-offre-edf-tempo-current-date-html-year', 0)?->nextSibling()?->nextSibling()?->nextSibling(); + $elementsDom = $ulDom?->find('li'); + if ($elementsDom && count($elementsDom) === 3) { + foreach ($elementsDom as $elementDom) { + $item = []; + + $matches = []; + preg_match_all('/Jour (.*) : Heures (.*) : (.*) € \/ Heures (.*) : (.*) €/um', $elementDom->innertext, $matches, PREG_SET_ORDER, 0); + + if ($matches && count($matches[0]) === 6) { + for ($i = 0; $i < 2; $i++) { + $text = 'Jour ' . $matches[0][1] . ' - Heures ' . $matches[0][2 + 2 * $i] . ' : ' . $matches[0][3 + 2 * $i] . '€'; + $item['uri'] = self::URI . $contractUri; + $item['title'] = $text; + $item['author'] = self::MAINTAINER; + $item['content'] = $text; + $item['uid'] = hash('sha256', $item['title']); + + $this->items[] = $item; + } + } + } + } + + // powers + $ulPowerContract = $ul?->nextSibling()?->nextSibling(); + $elementsPowerContractDom = $ulPowerContract?->find('li'); + if ($elementsPowerContractDom && count($elementsPowerContractDom) === 4) { + foreach ($elementsPowerContractDom as $elementPowerContractDom) { + $item = []; + + $matches = []; + preg_match_all('/(.*) kVA : (.*) €/um', $elementPowerContractDom->innertext, $matches, PREG_SET_ORDER, 0); + + if ($matches && count($matches[0]) === 3) { + $text = $matches[0][1] . ' kVA : ' . $matches[0][2] . '€'; + $item['uri'] = self::URI . $contractUri; + $item['title'] = $text; + $item['author'] = self::MAINTAINER; + $item['content'] = $text; + $item['uid'] = hash('sha256', $item['title']); + + $this->items[] = $item; + } + } + } + } + + public function collectData() + { + $contract = $this->getKey('contract'); + $contractUri = $this->getInput('contract'); + $html = getSimpleHTMLDOM(self::URI . $contractUri); + + if ($contract === 'Tempo') { + $this->tempo($html, $contractUri); + } + } +} From d9984b45cb5a2dc52508d5e6174d409e7842bf55 Mon Sep 17 00:00:00 2001 From: Florent VIOLLEAU Date: Tue, 19 Dec 2023 02:13:29 +0100 Subject: [PATCH 2/4] [EdfPricesBridge] bad refactor --- bridges/EdfPricesBridge.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridges/EdfPricesBridge.php b/bridges/EdfPricesBridge.php index 985b164f36b..5268a8da466 100644 --- a/bridges/EdfPricesBridge.php +++ b/bridges/EdfPricesBridge.php @@ -70,7 +70,7 @@ private function tempo(simple_html_dom $html, string $contractUri): void } // powers - $ulPowerContract = $ul?->nextSibling()?->nextSibling(); + $ulPowerContract = $ulDom?->nextSibling()?->nextSibling(); $elementsPowerContractDom = $ulPowerContract?->find('li'); if ($elementsPowerContractDom && count($elementsPowerContractDom) === 4) { foreach ($elementsPowerContractDom as $elementPowerContractDom) { From 1dbc8ed6f9f8f70a6a155553238fcf25fefa3d87 Mon Sep 17 00:00:00 2001 From: Florent VIOLLEAU Date: Mon, 25 Dec 2023 23:53:13 +0100 Subject: [PATCH 3/4] [EdfPricesBridge] support php 7.4 --- bridges/EdfPricesBridge.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bridges/EdfPricesBridge.php b/bridges/EdfPricesBridge.php index 5268a8da466..f67ed30b1c7 100644 --- a/bridges/EdfPricesBridge.php +++ b/bridges/EdfPricesBridge.php @@ -27,7 +27,7 @@ class EdfPricesBridge extends BridgeAbstract private function tempo(simple_html_dom $html, string $contractUri): void { // current color and next - $daysDom = $html->find('#calendrier', 0)?->nextSibling()?->find('.card--ejp'); + $daysDom = $html->find('#calendrier', 0)->nextSibling()->find('.card--ejp'); if ($daysDom && count($daysDom) === 2) { foreach ($daysDom as $dayDom) { $day = trim($dayDom->find('.card__title', 0)->innertext) . '/' . (new \DateTime('now'))->format(('Y')); @@ -45,8 +45,8 @@ private function tempo(simple_html_dom $html, string $contractUri): void } // colors - $ulDom = $html->find('#tarif-de-l-offre-edf-tempo-current-date-html-year', 0)?->nextSibling()?->nextSibling()?->nextSibling(); - $elementsDom = $ulDom?->find('li'); + $ulDom = $html->find('#tarif-de-l-offre-edf-tempo-current-date-html-year', 0)->nextSibling()->nextSibling()->nextSibling(); + $elementsDom = $ulDom->find('li'); if ($elementsDom && count($elementsDom) === 3) { foreach ($elementsDom as $elementDom) { $item = []; @@ -70,8 +70,8 @@ private function tempo(simple_html_dom $html, string $contractUri): void } // powers - $ulPowerContract = $ulDom?->nextSibling()?->nextSibling(); - $elementsPowerContractDom = $ulPowerContract?->find('li'); + $ulPowerContract = $ulDom->nextSibling()->nextSibling(); + $elementsPowerContractDom = $ulPowerContract->find('li'); if ($elementsPowerContractDom && count($elementsPowerContractDom) === 4) { foreach ($elementsPowerContractDom as $elementPowerContractDom) { $item = []; From fd2df60809472f47fd637e4e002d99fdf61f4c52 Mon Sep 17 00:00:00 2001 From: Florent VIOLLEAU Date: Sun, 8 Dec 2024 15:54:50 +0100 Subject: [PATCH 4/4] [EdfPrices Bridge] fix errors --- bridges/EdfPricesBridge.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bridges/EdfPricesBridge.php b/bridges/EdfPricesBridge.php index f67ed30b1c7..18e6f8e66e0 100644 --- a/bridges/EdfPricesBridge.php +++ b/bridges/EdfPricesBridge.php @@ -45,14 +45,14 @@ private function tempo(simple_html_dom $html, string $contractUri): void } // colors - $ulDom = $html->find('#tarif-de-l-offre-edf-tempo-current-date-html-year', 0)->nextSibling()->nextSibling()->nextSibling(); + $ulDom = $html->find('#tarif-de-l-offre-tempo-edf-template-date-now-y', 0)->nextSibling()->nextSibling()->nextSibling(); $elementsDom = $ulDom->find('li'); if ($elementsDom && count($elementsDom) === 3) { 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', $elementDom->innertext, $matches, PREG_SET_ORDER, 0); if ($matches && count($matches[0]) === 6) { for ($i = 0; $i < 2; $i++) {