[DealabsBridge] Conform to coding policy
- If no there are no results, an explicit message is now returned - Commas are now following the coding policy - Lines are no longer more than 80 chars when possible
This commit is contained in:
parent
fe48340327
commit
d7a1dca004
1 changed files with 48 additions and 9 deletions
|
@ -2,12 +2,24 @@
|
||||||
class DealabsBridge extends BridgeAbstract {
|
class DealabsBridge extends BridgeAbstract {
|
||||||
const NAME = 'Dealabs search bridge';
|
const NAME = 'Dealabs search bridge';
|
||||||
const URI = 'https://www.dealabs.com/';
|
const URI = 'https://www.dealabs.com/';
|
||||||
const DESCRIPTION = 'Return the Dealabs search result using keywords, with/without expired deals, with/without shop deals and by category';
|
const DESCRIPTION = 'Return the Dealabs search result using keywords,'
|
||||||
|
. ' with/without expired deals, with/without shop deals and by'
|
||||||
|
. ' category';
|
||||||
const MAINTAINER = 'sysadminstory';
|
const MAINTAINER = 'sysadminstory';
|
||||||
const PARAMETERS = array( array (
|
const PARAMETERS = array( array (
|
||||||
'q' => array('name' => 'Mot(s) clé(s)', 'type' => 'text', 'required' => true ),
|
'q' => array(
|
||||||
'expired_choice' => array('name' => 'Afficher deals expirés', 'type' => 'checkbox'),
|
'name' => 'Mot(s) clé(s)',
|
||||||
'instore_choice' => array('name' => 'Afficher deals en magasin', 'type' => 'checkbox'),
|
'type' => 'text',
|
||||||
|
'required' => true
|
||||||
|
),
|
||||||
|
'expired_choice' => array(
|
||||||
|
'name' => 'Afficher deals expirés',
|
||||||
|
'type' => 'checkbox'
|
||||||
|
),
|
||||||
|
'instore_choice' => array(
|
||||||
|
'name' => 'Afficher deals en magasin',
|
||||||
|
'type' => 'checkbox'
|
||||||
|
),
|
||||||
'cat' => array(
|
'cat' => array(
|
||||||
'name' => 'Catégorie',
|
'name' => 'Catégorie',
|
||||||
'type' => 'list',
|
'type' => 'list',
|
||||||
|
@ -74,6 +86,7 @@ class DealabsBridge extends BridgeAbstract {
|
||||||
|
|
||||||
|
|
||||||
));
|
));
|
||||||
|
|
||||||
const CACHE_TIMEOUT = 3600;
|
const CACHE_TIMEOUT = 3600;
|
||||||
|
|
||||||
public function collectData(){
|
public function collectData(){
|
||||||
|
@ -93,16 +106,24 @@ class DealabsBridge extends BridgeAbstract {
|
||||||
or returnServerError('Could not request Dealabs.');
|
or returnServerError('Could not request Dealabs.');
|
||||||
$list = $html->find('article');
|
$list = $html->find('article');
|
||||||
if($list === null) {
|
if($list === null) {
|
||||||
return;
|
returnClientError('Your combination of parameters returned no results');
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($list as $deal) {
|
foreach($list as $deal) {
|
||||||
$item = array();
|
$item = array();
|
||||||
$item['uri'] = $deal->find('a.title',0)->href;
|
$item['uri'] = $deal->find('a.title', 0)->href;
|
||||||
$item['title'] = $deal->find('a.title', 0)->plaintext;
|
$item['title'] = $deal->find('a.title', 0)->plaintext;
|
||||||
$item['author'] = $deal->find('a.poster_link', 0)->plaintext;
|
$item['author'] = $deal->find('a.poster_link', 0)->plaintext;
|
||||||
$item['content'] = '<table><tr><td>' .$deal->find('div.image_part',0)->outertext . '</td><td>'. $deal->find('a.title',0)->outertext . $deal->find('p.description',0)->outertext .'</td><td>'. $deal->find('div.vote_part',0)->outertext . '</td></table>';
|
$item['content'] = '<table><tr><td>'
|
||||||
$item['timestamp'] = $this->relativeDateToTimestamp($deal->find('p.date_deal',0)->plaintext);
|
. $deal->find('div.image_part', 0)->outertext
|
||||||
|
. '</td><td>'
|
||||||
|
. $deal->find('a.title', 0)->outertext
|
||||||
|
. $deal->find('p.description', 0)->outertext
|
||||||
|
. '</td><td>'
|
||||||
|
. $deal->find('div.vote_part', 0)->outertext
|
||||||
|
. '</td></table>';
|
||||||
|
$item['timestamp'] = $this->relativeDateToTimestamp(
|
||||||
|
$deal->find('p.date_deal', 0)->plaintext);
|
||||||
$this->items[] = $item;
|
$this->items[] = $item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +131,25 @@ class DealabsBridge extends BridgeAbstract {
|
||||||
|
|
||||||
private function relativeDateToTimestamp($str) {
|
private function relativeDateToTimestamp($str) {
|
||||||
$date = new DateTime();
|
$date = new DateTime();
|
||||||
$date->modify(str_replace(array('il y a ', 'min' , 'h', 'jour', 'jours', 'mois', 'ans'), array('-', 'minute', 'hour', 'day', 'month', 'year'), $str));
|
$search = array(
|
||||||
|
'il y a ',
|
||||||
|
'min',
|
||||||
|
'h',
|
||||||
|
'jour',
|
||||||
|
'jours',
|
||||||
|
'mois',
|
||||||
|
'ans'
|
||||||
|
);
|
||||||
|
$replace = array(
|
||||||
|
'-',
|
||||||
|
'minute',
|
||||||
|
'hour',
|
||||||
|
'day',
|
||||||
|
'month',
|
||||||
|
'year'
|
||||||
|
);
|
||||||
|
|
||||||
|
$date->modify(str_replace($search, $replace, $str));
|
||||||
return $date->getTimestamp();
|
return $date->getTimestamp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue