Dealabs : Get Groupes Feeds and Feed name is set according to parameters

* Feed name use now the user parameters
* New way to get Deals : using the Groupe defined on the Website
* Code refactoring to avoid duplicate code
This commit is contained in:
sysadminstory 2018-02-14 22:52:30 +01:00
parent 0c7e35ceff
commit bc9f37d943

View File

@ -4,7 +4,8 @@ class DealabsBridge extends BridgeAbstract {
const URI = 'https://www.dealabs.com/'; const URI = 'https://www.dealabs.com/';
const DESCRIPTION = 'Return the Dealabs search result using keywords'; const DESCRIPTION = 'Return the Dealabs search result using keywords';
const MAINTAINER = 'sysadminstory'; const MAINTAINER = 'sysadminstory';
const PARAMETERS = array( array ( const PARAMETERS = array(
'Recherche par Mot(s) clé(s)' => array (
'q' => array( 'q' => array(
'name' => 'Mot(s) clé(s)', 'name' => 'Mot(s) clé(s)',
'type' => 'text', 'type' => 'text',
@ -35,19 +36,88 @@ class DealabsBridge extends BridgeAbstract {
'required' => 'false', 'required' => 'false',
'defaultValue' => '' 'defaultValue' => ''
), ),
)); ),
'Deals par groupe' => array(
'groupe' => array(
'name' => 'Groupe',
'type' => 'list',
'required' => 'true',
'title' => 'Groupe dont il faut afficher les deals',
'values' => array(
'Accessoires & gadgets' => 'accessoires-gadgets',
'Alimentation & boissons' => 'alimentation-boissons',
'Animaux' => 'animaux',
'Applis & logiciels' => 'applis-logiciels',
'Consoles & jeux vidéo' => 'consoles-jeux-video',
'Culture & divertissement' => 'culture-divertissement',
'Gratuit' => 'gratuit',
'Image, son & vidéo' => 'image-son-video',
'Informatique' => 'informatique',
'Jeux & jouets' => 'jeux-jouets',
'Maison & jardin' => 'maison-jardin',
'Mode & accessoires' => 'mode-accessoires',
'Santé & cosmétiques' => 'hygiene-sante-cosmetiques',
'Services divers' => 'services-divers',
'Sports & plein air' => 'sports-plein-air',
'Téléphonie' => 'telephonie',
'Voyages & sorties' => 'voyages-sorties-restaurants'
)
),
'ordre' => array(
'name' => 'Trier par',
'type' => 'list',
'required' => 'true',
'title' => 'Ordre de tri des deals',
'values' => array(
'Du deal le plus Hot au moins Hot' => '',
'Du deal le plus récent au plus ancien' => '-nouveaux',
'Du deal le plus commentés au moins commentés' => '-commentes'
)
)
)
);
const CACHE_TIMEOUT = 3600; const CACHE_TIMEOUT = 3600;
public function collectData(){ public function collectData(){
switch($this->queriedContext) {
case 'Recherche par Mot(s) clé(s)':
return $this->collectDataMotsCles();
break;
case 'Deals par groupe':
return $this->collectDataGroupe();
break;
}
}
/**
* Get the Deal data from the choosen groupe in the choose order
*/
public function collectDataGroupe()
{
$groupe = $this->getInput('groupe');
$ordre = $this->getInput('ordre');
$url = self::URI
. '/groupe/' . $groupe . $ordre;
$this->collectDeals($url);
}
/**
* Get the Deal data from the choosen keywords and parameters
*/
public function collectDataMotsCles()
{
$q = $this->getInput('q'); $q = $this->getInput('q');
$hide_expired = $this->getInput('hide_expired'); $hide_expired = $this->getInput('hide_expired');
$hide_local = $this->getInput('hide_local'); $hide_local = $this->getInput('hide_local');
$priceFrom = $this->getInput('priceFrom'); $priceFrom = $this->getInput('priceFrom');
$priceTo = $this->getInput('priceFrom'); $priceTo = $this->getInput('priceFrom');
/* Event if the original website uses POST with the search page, GET works too */ /* Even if the original website uses POST with the search page, GET works too */
$html = getSimpleHTMLDOM(self::URI $url = self::URI
. '/search/advanced?q=' . '/search/advanced?q='
. urlencode($q) . urlencode($q)
. '&hide_expired='. $hide_expired . '&hide_expired='. $hide_expired
@ -59,7 +129,15 @@ class DealabsBridge extends BridgeAbstract {
* sort_by : Sort the search by new deals * sort_by : Sort the search by new deals
* time_frame : Search will not be on a limited timeframe * time_frame : Search will not be on a limited timeframe
*/ */
. '&search_fields[]=1&search_fields[]=2&search_fields[]=3&sort_by=new&time_frame=0') . '&search_fields[]=1&search_fields[]=2&search_fields[]=3&sort_by=new&time_frame=0';
$this->collectDeals($url);
}
/**
* Get the Deal data using the given URL
*/
public function collectDeals($url){
$html = getSimpleHTMLDOM($url)
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) {
@ -320,4 +398,19 @@ class DealabsBridge extends BridgeAbstract {
return $date->getTimestamp(); return $date->getTimestamp();
} }
public function getName(){
switch($this->queriedContext){
case 'Recherche par Mot(s) clé(s)':
return self::NAME . ' - Recherche : '. $this->getInput('q') ;
break;
case 'Deals par groupe':
$values = self::PARAMETERS['Deals par groupe']['groupe']['values'];
$groupe = array_search($this->getInput('groupe'), $values);
return self::NAME . ' - Groupe : '. $groupe;
break;
default: // Return default value
return self::NAME;
}
}
} }