aboutsummaryrefslogtreecommitdiff
path: root/bridges/EdfPricesBridge.php
diff options
context:
space:
mode:
Diffstat (limited to 'bridges/EdfPricesBridge.php')
-rw-r--r--bridges/EdfPricesBridge.php235
1 files changed, 196 insertions, 39 deletions
diff --git a/bridges/EdfPricesBridge.php b/bridges/EdfPricesBridge.php
index f67ed30b..06cd30b7 100644
--- a/bridges/EdfPricesBridge.php
+++ b/bridges/EdfPricesBridge.php
@@ -12,8 +12,28 @@ class EdfPricesBridge extends BridgeAbstract
'contract' => [
'name' => 'Choisir un contrat',
'type' => 'list',
- // we can add later HCHP, EJP, base
- 'values' => ['Tempo' => '/energie/edf/tarifs/tempo'],
+ // we can add later more option prices
+ 'values' => [
+ 'Base' => '/energie/edf/tarifs/tarif-bleu#base',
+ 'HPHC' => '/energie/edf/tarifs/tarif-bleu#hphc',
+ 'EJP' => '/energie/edf/tarifs/tarif-bleu#ejp',
+ 'Tempo' => '/energie/edf/tarifs/tempo'
+ ],
+ ],
+ 'power' => [
+ 'name' => 'Choisir une puissance',
+ 'type' => 'list',
+ 'values' => [
+ '3 kVA' => 3,
+ '6 kVA' => 6,
+ '9 kVA' => 9,
+ '12 kVA' => 12,
+ '15 kVA' => 15,
+ '18 kVA' => 18,
+ '24 kVA' => 24,
+ '30 kVA' => 30,
+ '36 kVA' => 36
+ ]
]
]
];
@@ -24,36 +44,20 @@ class EdfPricesBridge extends BridgeAbstract
* @param string $contractUri
* @return void
*/
- private function tempo(simple_html_dom $html, string $contractUri): void
+ private function tempo(simple_html_dom $html, string $contractUri, int $power): 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();
+ $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) {
+ // 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', $elementDom->innertext, $matches, PREG_SET_ORDER, 0);
+ // for tempo contract we have 2x3 colors
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] . '€';
@@ -69,26 +73,166 @@ class EdfPricesBridge extends BridgeAbstract
}
}
- // powers
- $ulPowerContract = $ulDom->nextSibling()->nextSibling();
- $elementsPowerContractDom = $ulPowerContract->find('li');
- if ($elementsPowerContractDom && count($elementsPowerContractDom) === 4) {
- foreach ($elementsPowerContractDom as $elementPowerContractDom) {
+ // add subscription power info
+ $tablePrices = $ulDom->nextSibling()->nextSibling()->nextSibling()->find('.table--responsive', 0);
+ $this->addSubscriptionPowerInfo($tablePrices, $contractUri, $power, 7);
+ }
+
+ /**
+ * @param simple_html_dom $html
+ * @param string $contractUri
+ * @return void
+ */
+ private function base(simple_html_dom $html, string $contractUri, int $power): void
+ {
+ $tablePrices = $html
+ ->find('#grille-tarifaire-et-prix-du-kwh-du-tarif-reglemente-edf-en-option-base', 0)
+ ->nextSibling()
+ ->nextSibling()
+ ->nextSibling();
+
+ $prices = $tablePrices->find('.table--stripped tbody tr');
+ // last element is useless because part of another table
+ array_pop($prices);
+
+ // price per kWh is same for all powers
+ if ($prices && count($prices) === 9) {
+ $item = [];
+
+ $text = 'Base : ' . $prices[0]->children(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;
+ }
+
+ $this->addSubscriptionPowerInfo($tablePrices, $contractUri, $power, 9);
+ }
+
+ /**
+ * @param simple_html_dom $html
+ * @param string $contractUri
+ * @return void
+ */
+ private function hphc(simple_html_dom $html, string $contractUri, int $power): void
+ {
+ $tablePrices = $html
+ ->find('#grille-tarifaire-et-prix-du-kwh-du-tarif-reglemente-edf-en-option-heures-pleines-heures-creuses', 0)
+ ->nextSibling()
+ ->nextSibling()
+ ->nextSibling();
+
+ $prices = $tablePrices->find('.table--stripped tbody tr');
+ // last element is useless because part of another table
+ array_pop($prices);
+
+ // price per kWh is same for all powers
+ if ($prices && count($prices) === 8) {
+ $values = ['HC', 'HP'];
+ foreach ($values as $key => $value) {
+ $i++;
$item = [];
- $matches = [];
- preg_match_all('/(.*) kVA : (.*) €/um', $elementPowerContractDom->innertext, $matches, PREG_SET_ORDER, 0);
+ $text = $values[$key] . ' : ' . $prices[0]->children($key + 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;
+ }
+ }
+
+ $this->addSubscriptionPowerInfo($tablePrices, $contractUri, $power, 8);
+ }
+
+ /**
+ * @param simple_html_dom $html
+ * @param string $contractUri
+ * @return void
+ */
+ private function ejp(simple_html_dom $html, string $contractUri, int $power): void
+ {
+ $tablePrices = $html
+ ->find('#grille-tarifaire-et-prix-du-kwh-du-tarif-reglemente-edf-en-option-ejp', 0)
+ ->nextSibling()
+ ->nextSibling()
+ ->nextSibling();
+
+ $prices = $tablePrices->find('.table--stripped tbody tr');
+ // last element is useless because part of another table
+ array_pop($prices);
- 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']);
+ // price per kWh is same for all powers
+ if ($prices && count($prices) === 5) {
+ $values = ['Non EJP', 'EJP'];
+ foreach ($values as $key => $value) {
+ $i++;
+ $item = [];
+
+ $text = $values[$key] . ' : ' . $prices[0]->children($key + 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;
+ $this->items[] = $item;
+ }
+ }
+
+ $this->addSubscriptionPowerInfo($tablePrices, $contractUri, $power, 5);
+ }
+
+ private function addSubscriptionPowerInfo(simple_html_dom_node $tablePrices, string $contractUri, int $power, int $numberOfPrices): void
+ {
+ $prices = $tablePrices->find('.table--stripped tbody tr');
+ // last element is useless because part of another table
+ array_pop($prices);
+
+ // 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
+ // 7 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;
+ $powerValue = (int)substr($powerText, 0, strpos($powerText, ' kVA'));
+
+ if ($powerValue !== $power) {
+ continue;
}
+
+ $item = [];
+
+ $text = $powerText . ' : ' . $price->children(1) . '/an';
+ $item['uri'] = self::URI . $contractUri;
+ $item['title'] = $text;
+ $item['author'] = self::MAINTAINER;
+ $item['content'] = $text;
+ $item['uid'] = hash('sha256', $item['title']);
+
+ $this->items[] = $item;
+ $powerFound = true;
+ break;
+ }
+
+ if (!$powerFound) {
+ $item = [];
+
+ $text = 'Pas de tarif abonnement pour cette puissance et ce contrat';
+ $item['uri'] = self::URI . $contractUri;
+ $item['title'] = $text;
+ $item['author'] = self::MAINTAINER;
+ $item['content'] = $text;
+ $item['uid'] = hash('sha256', $item['title']);
+
+ $this->items[] = $item;
}
}
}
@@ -97,10 +241,23 @@ class EdfPricesBridge extends BridgeAbstract
{
$contract = $this->getKey('contract');
$contractUri = $this->getInput('contract');
+ $power = $this->getInput('power');
$html = getSimpleHTMLDOM(self::URI . $contractUri);
if ($contract === 'Tempo') {
- $this->tempo($html, $contractUri);
+ $this->tempo($html, $contractUri, $power);
+ }
+
+ if ($contract === 'Base') {
+ $this->base($html, $contractUri, $power);
+ }
+
+ if ($contract === 'HPHC') {
+ $this->hphc($html, $contractUri, $power);
+ }
+
+ if ($contract === 'EJP') {
+ $this->ejp($html, $contractUri, $power);
}
}
}