mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-01-09 13:07:27 +03:00
[EdfPrices Bridge] add HC/HP, base and EJP (#4369)
* [EdfPrices Bridge] add HC/HP, base and EJP * [EdfPrices Bridge] lint * [EdfPrices Bridge] fix missing variable
This commit is contained in:
parent
7d544f1fab
commit
b4a63e7040
1 changed files with 194 additions and 37 deletions
|
@ -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-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);
|
||||
|
||||
// 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,18 +73,159 @@ 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 = [];
|
||||
|
||||
$matches = [];
|
||||
preg_match_all('/(.*) kVA : (.*) €/um', $elementPowerContractDom->innertext, $matches, PREG_SET_ORDER, 0);
|
||||
$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']);
|
||||
|
||||
if ($matches && count($matches[0]) === 3) {
|
||||
$text = $matches[0][1] . ' kVA : ' . $matches[0][2] . '€';
|
||||
$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 = [];
|
||||
|
||||
$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);
|
||||
|
||||
// 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->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;
|
||||
|
@ -91,16 +236,28 @@ class EdfPricesBridge extends BridgeAbstract
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function collectData()
|
||||
{
|
||||
$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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue