mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2024-11-27 03:50:42 +03:00
[IdealoBridge] Really fix Logic and enhance Feed Content (#4321)
- Fix Feed Title generation (wrong usage of loadCacheValue) - Use a more reliable way to get New and Used Price - If no new Price and no Used Price are present in the page, then don't delete previous New Price and previous Used Price - If there is no New Price and no Used Price, then return no Feed Item - Fix the "now" date format - Make the Feed Item Title more readable - Use the Product Link as the Feed URL
This commit is contained in:
parent
dd165ea9d1
commit
6c86e2c1f7
1 changed files with 32 additions and 16 deletions
|
@ -49,7 +49,7 @@ class IdealoBridge extends BridgeAbstract
|
||||||
$cacheDuration = 604800;
|
$cacheDuration = 604800;
|
||||||
$link = $this->getInput('Link');
|
$link = $this->getInput('Link');
|
||||||
$keyTITLE = $link . 'TITLE';
|
$keyTITLE = $link . 'TITLE';
|
||||||
$product = $this->loadCacheValue($keyTITLE, $cacheDuration);
|
$product = $this->loadCacheValue($keyTITLE);
|
||||||
|
|
||||||
// The cache does not contain the title of the bridge, we must get it and save it in the cache
|
// The cache does not contain the title of the bridge, we must get it and save it in the cache
|
||||||
if ($product === null) {
|
if ($product === null) {
|
||||||
|
@ -147,30 +147,32 @@ class IdealoBridge extends BridgeAbstract
|
||||||
$OldPriceUsed = $this->loadCacheValue($KeyUSED);
|
$OldPriceUsed = $this->loadCacheValue($KeyUSED);
|
||||||
|
|
||||||
// First button contains the new price. Found at oopStage-conditionButton-wrapper-text class (.)
|
// First button contains the new price. Found at oopStage-conditionButton-wrapper-text class (.)
|
||||||
$FirstButton = $html->find('.oopStage-conditionButton-wrapper-text', 0);
|
$ActualNewPrice = $html->find('div[id=oopStage-conditionButton-new]', 0);
|
||||||
if ($FirstButton) {
|
// Second Button contains the used product price
|
||||||
$PriceNew = $FirstButton->find('strong', 0)->plaintext;
|
$ActualUsedPrice = $html->find('div[id=oopStage-conditionButton-used]', 0);
|
||||||
|
|
||||||
|
if ($ActualNewPrice) {
|
||||||
|
$PriceNew = $ActualNewPrice->find('strong', 0)->plaintext;
|
||||||
// Save current price
|
// Save current price
|
||||||
$this->saveCacheValue($KeyNEW, $PriceNew);
|
$this->saveCacheValue($KeyNEW, $PriceNew);
|
||||||
} else if ($FirstButton === null) {
|
} else if ($ActualNewPrice === null && $ActualUsedPrice !== null) {
|
||||||
// In case there is no actual New Price delete the previous value in the cache
|
// In case there is no actual New Price and a Ured Price exists, then delete the previous value in the cache
|
||||||
$this->cache->delete($this->getShortName() . '_' . $KeyNEW);
|
$this->cache->delete($this->getShortName() . '_' . $KeyNEW);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Second Button contains the used product price
|
// Second Button contains the used product price
|
||||||
$SecondButton = $html->find('.oopStage-conditionButton-wrapper-text', 1);
|
if ($ActualUsedPrice) {
|
||||||
if ($SecondButton) {
|
$PriceUsed = $ActualUsedPrice->find('strong', 0)->plaintext;
|
||||||
$PriceUsed = $SecondButton->find('strong', 0)->plaintext;
|
|
||||||
// Save current price
|
// Save current price
|
||||||
$this->saveCacheValue($KeyUSED, $PriceUsed);
|
$this->saveCacheValue($KeyUSED, $PriceUsed);
|
||||||
} else if ($SecondButton === null) {
|
} else if ($ActualUsedPrice === null && $ActualNewPrice !== null) {
|
||||||
// In case there is no actual Used Price delete the previous value in the cache
|
// In case there is no actual Used Price and a New Price exists, then delete the previous value in the cache
|
||||||
$this->cache->delete($this->getShortName() . '_' . $KeyUSED);
|
$this->cache->delete($this->getShortName() . '_' . $KeyUSED);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only continue if a price has changed
|
// Only continue if a price has changed and there exists a New or Used price (sometimes no new Price _and_ Used Price are shown)
|
||||||
if ($PriceNew != $OldPriceNew || $PriceUsed != $OldPriceUsed) {
|
if (!($ActualNewPrice === null && $ActualUsedPrice === null ) && ($PriceNew != $OldPriceNew || $PriceUsed != $OldPriceUsed)) {
|
||||||
// Get Product Image
|
// Get Product Image
|
||||||
$image = $html->find('.datasheet-cover-image', 0)->src;
|
$image = $html->find('.datasheet-cover-image', 0)->src;
|
||||||
|
|
||||||
|
@ -198,9 +200,9 @@ class IdealoBridge extends BridgeAbstract
|
||||||
$content .= "<img src=$image>";
|
$content .= "<img src=$image>";
|
||||||
|
|
||||||
|
|
||||||
$now = date('d.m.j H:m');
|
$now = date('d/m/Y H:i');
|
||||||
|
|
||||||
$Pricealarm = 'Pricealarm %s: %s %s %s';
|
$Pricealarm = 'Pricealarm %s: %s %s - %s';
|
||||||
|
|
||||||
// Currently under Max new price
|
// Currently under Max new price
|
||||||
if ($this->getInput('MaxPriceNew') != '') {
|
if ($this->getInput('MaxPriceNew') != '') {
|
||||||
|
@ -247,7 +249,7 @@ class IdealoBridge extends BridgeAbstract
|
||||||
$title .= 'USED' . $this->getPriceTrend($PriceUsed, $OldPriceUsed) . ' ';
|
$title .= 'USED' . $this->getPriceTrend($PriceUsed, $OldPriceUsed) . ' ';
|
||||||
}
|
}
|
||||||
$title .= $Productname;
|
$title .= $Productname;
|
||||||
$title .= ' ';
|
$title .= ' - ';
|
||||||
$title .= $now;
|
$title .= $now;
|
||||||
|
|
||||||
$item = [
|
$item = [
|
||||||
|
@ -275,4 +277,18 @@ class IdealoBridge extends BridgeAbstract
|
||||||
return parent::getName();
|
return parent::getName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the RSS Feed URL according to the parameters
|
||||||
|
* @return string the RSS feed URL
|
||||||
|
*/
|
||||||
|
public function getURI()
|
||||||
|
{
|
||||||
|
switch ($this->queriedContext) {
|
||||||
|
case '0':
|
||||||
|
return $this->getInput('Link');
|
||||||
|
default:
|
||||||
|
return parent::getURI();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue