From fe48340327c7a6cc3f816c71936bbe8f4308c472 Mon Sep 17 00:00:00 2001 From: sysadminstory Date: Tue, 5 Sep 2017 21:03:21 +0200 Subject: [PATCH 1/4] [DealabsBridge] Add new bridge --- bridges/DealabsBridge.php | 134 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 bridges/DealabsBridge.php diff --git a/bridges/DealabsBridge.php b/bridges/DealabsBridge.php new file mode 100644 index 0000000..bb2bfff --- /dev/null +++ b/bridges/DealabsBridge.php @@ -0,0 +1,134 @@ + array('name' => 'Mot(s) clé(s)', '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( + 'name' => 'Catégorie', + 'type' => 'list', + 'values' => array( + 'Toutes les catégories' => '', + 'High-tech' => array( + 'Tous' => 'c2', + 'Informatique' => 's3', + 'Téléphonie' => 's4', + 'Accessoires, consommables' => 's6', + 'Gadgets' => 's8', + 'Applications, logiciels' => 's46' + ), + 'Audiovisuel' => array( + 'Tous' => 'c5', + 'Image et son' => 's9', + 'Photo, caméscopes' => 's10', + 'CD, DVD, Blu-ray' => 's11', + 'Jeux vidéo, consoles' => 's12' + ), + 'Loisirs' => array( + 'Tous' => 'c7', + 'Jeux, jouets' => 's13', + 'Livres, papeterie' => 's14', + 'Plein air' => 's15', + 'Sport' => 's35', + 'Auto/Moto, accessoires' => 's37', + 'Animaux, accessoires' => 's47', + 'Instruments de musique' => 's48' + ), + 'Mode' => array( + 'Tous' => 'c16', + 'Homme' => 's17', + 'Femme' => 's18', + 'Mixte' => 's50', + 'Enfants' => 's19', + 'Puériculture' => 's36', + 'Beauté, santé' => 's21', + 'Bijoux, accessoires' => 's20', + 'Bagagerie' => 's38' + ), + 'Maison' => array( + 'Tous' => 'c23', + 'Meuble, literie, déco' => 's24', + 'Cuisine, art de la table' => 's25', + 'Électroménager' => 's26', + 'Bricolage' => 's27', + 'Jardin' => 's28' + ), + 'Services' => array( + 'Tous' => 'c51', + 'Voyages' => 's57', + 'Hébergement, restauration' => 's52', + 'Sorties' => 's53', + 'Presse' => 's24', + 'Bien-être' => 's55', + 'Transport, expédition' => 's56', + 'Autres' => 's58' + ), + 'Épicerie' => 'c31' + + ) + ) + + + )); + const CACHE_TIMEOUT = 3600; + + public function collectData(){ + $q = $this->getInput('q'); + + $expired_choice = $this->getInput('expired_choice'); + $instore_choice = $this->getInput('instore_choice'); + $cat_subcat = $this->getInput('cat'); + $html = getSimpleHTMLDOM(self::URI + . '/search/?q=' + . urlencode($q) + . '&hide_expired=' + . $expired_choice + . '&hide_instore=' + . $instore_choice + . '&' . $this->getCatSubcatParam($cat_subcat)) + or returnServerError('Could not request Dealabs.'); + $list = $html->find('article'); + if($list === null) { + return; + } + + foreach($list as $deal) { + $item = array(); + $item['uri'] = $deal->find('a.title',0)->href; + $item['title'] = $deal->find('a.title', 0)->plaintext; + $item['author'] = $deal->find('a.poster_link', 0)->plaintext; + $item['content'] = '
' .$deal->find('div.image_part',0)->outertext . ''. $deal->find('a.title',0)->outertext . $deal->find('p.description',0)->outertext .''. $deal->find('div.vote_part',0)->outertext . '
'; + $item['timestamp'] = $this->relativeDateToTimestamp($deal->find('p.date_deal',0)->plaintext); + $this->items[] = $item; + } + + } + + private function relativeDateToTimestamp($str) { + $date = new DateTime(); + $date->modify(str_replace(array('il y a ', 'min' , 'h', 'jour', 'jours', 'mois', 'ans'), array('-', 'minute', 'hour', 'day', 'month', 'year'), $str)); + return $date->getTimestamp(); + } + + private function getCatSubcatParam($str) { + if(strlen($str) >=2) { + if(substr($str, 0, 1) == 'c') { + $var_name = 'cat[]'; + } + else if(substr($str, 0, 1) == 's') { + $var_name = 'sub_cat[]'; + } + $value = substr($str, 1); + return $var_name .'='. $value; + } + else + { + return ''; + } + } + +} From d7a1dca0048b6a4eef59600e3064a47dc0b3f82c Mon Sep 17 00:00:00 2001 From: sysadminstory Date: Tue, 19 Sep 2017 02:08:22 +0200 Subject: [PATCH 2/4] [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 --- bridges/DealabsBridge.php | 57 ++++++++++++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 9 deletions(-) diff --git a/bridges/DealabsBridge.php b/bridges/DealabsBridge.php index bb2bfff..ee6bd1a 100644 --- a/bridges/DealabsBridge.php +++ b/bridges/DealabsBridge.php @@ -2,12 +2,24 @@ class DealabsBridge extends BridgeAbstract { const NAME = 'Dealabs search bridge'; 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 PARAMETERS = array( array ( - 'q' => array('name' => 'Mot(s) clé(s)', 'type' => 'text', 'required' => true ), - 'expired_choice' => array('name' => 'Afficher deals expirés', 'type' => 'checkbox'), - 'instore_choice' => array('name' => 'Afficher deals en magasin', 'type' => 'checkbox'), + 'q' => array( + 'name' => 'Mot(s) clé(s)', + '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( 'name' => 'Catégorie', 'type' => 'list', @@ -74,6 +86,7 @@ class DealabsBridge extends BridgeAbstract { )); + const CACHE_TIMEOUT = 3600; public function collectData(){ @@ -93,16 +106,24 @@ class DealabsBridge extends BridgeAbstract { or returnServerError('Could not request Dealabs.'); $list = $html->find('article'); if($list === null) { - return; + returnClientError('Your combination of parameters returned no results'); } foreach($list as $deal) { $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['author'] = $deal->find('a.poster_link', 0)->plaintext; - $item['content'] = '
' .$deal->find('div.image_part',0)->outertext . ''. $deal->find('a.title',0)->outertext . $deal->find('p.description',0)->outertext .''. $deal->find('div.vote_part',0)->outertext . '
'; - $item['timestamp'] = $this->relativeDateToTimestamp($deal->find('p.date_deal',0)->plaintext); + $item['content'] = '
' + . $deal->find('div.image_part', 0)->outertext + . '' + . $deal->find('a.title', 0)->outertext + . $deal->find('p.description', 0)->outertext + . '' + . $deal->find('div.vote_part', 0)->outertext + . '
'; + $item['timestamp'] = $this->relativeDateToTimestamp( + $deal->find('p.date_deal', 0)->plaintext); $this->items[] = $item; } @@ -110,7 +131,25 @@ class DealabsBridge extends BridgeAbstract { private function relativeDateToTimestamp($str) { $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(); } From 5cbd3635970917976961a032a34db927a6586530 Mon Sep 17 00:00:00 2001 From: sysadminstory Date: Tue, 17 Oct 2017 23:30:27 +0200 Subject: [PATCH 3/4] Coding style fix Fixed the bridge to follow the project coding style --- bridges/DealabsBridge.php | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/bridges/DealabsBridge.php b/bridges/DealabsBridge.php index ee6bd1a..a2e9f50 100644 --- a/bridges/DealabsBridge.php +++ b/bridges/DealabsBridge.php @@ -2,9 +2,8 @@ class DealabsBridge extends BridgeAbstract { const NAME = 'Dealabs search bridge'; 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 PARAMETERS = array( array ( 'q' => array( @@ -154,18 +153,15 @@ class DealabsBridge extends BridgeAbstract { } private function getCatSubcatParam($str) { - if(strlen($str) >=2) { + if(strlen($str) >= 2) { if(substr($str, 0, 1) == 'c') { $var_name = 'cat[]'; - } - else if(substr($str, 0, 1) == 's') { + } else if(substr($str, 0, 1) == 's') { $var_name = 'sub_cat[]'; } $value = substr($str, 1); return $var_name .'='. $value; - } - else - { + } else { return ''; } } From 2bb9a29ddc5f0cfc9dec64809b32a6cbc685e508 Mon Sep 17 00:00:00 2001 From: sysadminstory Date: Tue, 17 Oct 2017 23:37:09 +0200 Subject: [PATCH 4/4] Delete usefull whitespace --- bridges/DealabsBridge.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridges/DealabsBridge.php b/bridges/DealabsBridge.php index a2e9f50..d6b1e66 100644 --- a/bridges/DealabsBridge.php +++ b/bridges/DealabsBridge.php @@ -85,7 +85,7 @@ class DealabsBridge extends BridgeAbstract { )); - + const CACHE_TIMEOUT = 3600; public function collectData(){