forked from RSS-Bridge/rss-bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IdealoBridge] New Bridge to track prices on idealo.de (RSS-Bridge#3786)
* [IdealoBridge] Created Checks the price of a given item on idealo.de. Can create an Alarm Message if a the price is lower than set or an Priceupdate if the price has changed. * Changed Exec and syntax * last fixes for remaining warning
- Loading branch information
Showing
1 changed file
with
180 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
<?php | ||
|
||
class IdealoBridge extends BridgeAbstract | ||
{ | ||
const NAME = 'Idealo.de Bridge'; | ||
const URI = 'https://www.idealo.de'; | ||
const DESCRIPTION = 'Tracks the price for a product on idealo.de. Pricealarm if specific price is set'; | ||
const MAINTAINER = 'SebLaus'; | ||
const CACHE_TIMEOUT = 60 * 30; // 30 min | ||
const PARAMETERS = [ | ||
[ | ||
'Link' => [ | ||
'name' => 'Idealo.de Link to productpage', | ||
'required' => true, | ||
'exampleValue' => 'https://www.idealo.de/preisvergleich/OffersOfProduct/202007367_-s7-pro-ultra-roborock.html' | ||
], | ||
'ExcludeNew' => [ | ||
'name' => 'Priceupdate: Do not track new items', | ||
'type' => 'checkbox', | ||
'value' => 'c' | ||
], | ||
'ExcludeUsed' => [ | ||
'name' => 'Priceupdate: Do not track used items', | ||
'type' => 'checkbox', | ||
'value' => 'uc' | ||
], | ||
'MaxPriceNew' => [ | ||
'name' => 'Pricealarm: Maximum price for new Product', | ||
'type' => 'number' | ||
], | ||
'MaxPriceUsed' => [ | ||
'name' => 'Pricealarm: Maximum price for used Product', | ||
'type' => 'number' | ||
], | ||
] | ||
]; | ||
|
||
public function getIcon() | ||
{ | ||
return 'https://cdn.idealo.com/storage/ids-assets/ico/favicon.ico'; | ||
} | ||
|
||
public function collectData() | ||
{ | ||
$link = $this->getInput('Link'); | ||
$html = getSimpleHTMLDOM($link); | ||
|
||
// Get Productname | ||
$titleobj = $html->find('.oopStage-title', 0); | ||
$Productname = $titleobj->find('span', 0)->plaintext; | ||
|
||
// Create product specific Cache Keys with the link | ||
$KeyNEW = $link; | ||
$KeyNEW .= 'NEW'; | ||
|
||
$KeyUSED = $link; | ||
$KeyUSED .= 'USED'; | ||
|
||
// Load previous Price | ||
$OldPriceNew = $this->loadCacheValue($KeyNEW); | ||
$OldPriceUsed = $this->loadCacheValue($KeyUSED); | ||
|
||
// First button is new. Found at oopStage-conditionButton-wrapper-text class (.) | ||
$FirstButton = $html->find('.oopStage-conditionButton-wrapper-text', 0); | ||
if ($FirstButton) { | ||
$PriceNew = $FirstButton->find('strong', 0)->plaintext; | ||
} | ||
|
||
// Second Button is used | ||
$SecondButton = $html->find('.oopStage-conditionButton-wrapper-text', 1); | ||
if ($SecondButton) { | ||
$PriceUsed = $SecondButton->find('strong', 0)->plaintext; | ||
} | ||
|
||
// Only continue if a price has changed | ||
if ($PriceNew != $OldPriceNew || $PriceUsed != $OldPriceUsed) { | ||
// Get Product Image | ||
$image = $html->find('.datasheet-cover-image', 0)->src; | ||
|
||
// Generate Content | ||
if ($PriceNew > 1) { | ||
$content = "<p><b>Price New:</b><br>$PriceNew</p>"; | ||
$content .= "<p><b>Price Newbefore:</b><br>$OldPriceNew</p>"; | ||
} | ||
|
||
if ($this->getInput('MaxPriceNew') != '') { | ||
$content .= sprintf('<p><b>Max Price Used:</b><br>%s,00 €</p>', $this->getInput('MaxPriceNew')); | ||
} | ||
|
||
if ($PriceUsed > 1) { | ||
$content .= "<p><b>Price Used:</b><br>$PriceUsed</p>"; | ||
$content .= "<p><b>Price Used before:</b><br>$OldPriceUsed</p>"; | ||
} | ||
|
||
if ($this->getInput('MaxPriceUsed') != '') { | ||
$content .= sprintf('<p><b>Max Price Used:</b><br>%s,00 €</p>', $this->getInput('MaxPriceUsed')); | ||
} | ||
|
||
$content .= "<img src=$image>"; | ||
|
||
|
||
$now = date('d.m.j H:m'); | ||
|
||
$Pricealarm = 'Pricealarm %s: %s %s %s'; | ||
|
||
// Currently under Max new price | ||
if ($this->getInput('MaxPriceNew') != '') { | ||
if ($PriceNew < $this->getInput('MaxPriceNew')) { | ||
$title = sprintf($Pricealarm, 'Used', $PriceNew, $Productname, $now); | ||
$item = [ | ||
'title' => $title, | ||
'uri' => $link, | ||
'content' => $content, | ||
'uid' => md5($title) | ||
]; | ||
$this->items[] = $item; | ||
} | ||
} | ||
|
||
// Currently under Max used price | ||
if ($this->getInput('MaxPriceUsed') != '') { | ||
if ($PriceUsed < $this->getInput('MaxPriceUsed')) { | ||
$title = sprintf($Pricealarm, 'Used', $PriceUsed, $Productname, $now); | ||
$item = [ | ||
'title' => $title, | ||
'uri' => $link, | ||
'content' => $content, | ||
'uid' => md5($title) | ||
]; | ||
$this->items[] = $item; | ||
} | ||
} | ||
|
||
// General Priceupdate | ||
if ($this->getInput('MaxPriceUsed') == '' && $this->getInput('MaxPriceNew') == '') { | ||
// check if a relevant pricechange happened | ||
if ( | ||
(!$this->getInput('ExcludeNew') && $PriceNew != $OldPriceNew ) || | ||
(!$this->getInput('ExcludeUsed') && $PriceUsed != $OldPriceUsed ) | ||
) { | ||
$title .= 'Priceupdate! '; | ||
|
||
if (!$this->getInput('ExcludeNew')) { | ||
if ($PriceNew < $OldPriceNew) { | ||
$title .= 'NEW:⬇ '; // Arrow Down Emoji | ||
} | ||
if ($PriceNew > $OldPriceNew) { | ||
$title .= 'NEW:⬆ '; // Arrow Up Emoji | ||
} | ||
} | ||
|
||
|
||
if (!$this->getInput('ExcludeUsed')) { | ||
if ($PriceUsed < $OldPriceUsed) { | ||
$title .= 'USED:⬇ '; // Arrow Down Emoji | ||
} | ||
if ($PriceUsed > $OldPriceUsed) { | ||
$title .= 'USED:⬆ '; // Arrow Up Emoji | ||
} | ||
} | ||
$title .= $Productname; | ||
$title .= ' '; | ||
$title .= $now; | ||
|
||
$item = [ | ||
'title' => $title, | ||
'uri' => $link, | ||
'content' => $content, | ||
'uid' => md5($title) | ||
]; | ||
$this->items[] = $item; | ||
} | ||
} | ||
} | ||
|
||
// Save current price | ||
$this->saveCacheValue($KeyNEW, $PriceNew); | ||
$this->saveCacheValue($KeyUSED, $PriceUsed); | ||
} | ||
} |