From 74b6dd37f93facb2a8a83e13cf0fdf28ecbba870 Mon Sep 17 00:00:00 2001 From: Damien Calesse Date: Sat, 30 Jul 2016 16:16:02 +0200 Subject: [PATCH 1/2] Add Sens Critique Bridge Get the movies, series, video games, books and musics news. --- bridges/SensCritiqueBridge.php | 146 +++++++++++++++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 bridges/SensCritiqueBridge.php diff --git a/bridges/SensCritiqueBridge.php b/bridges/SensCritiqueBridge.php new file mode 100644 index 00000000..c1aaa93e --- /dev/null +++ b/bridges/SensCritiqueBridge.php @@ -0,0 +1,146 @@ +maintainer = "kranack"; + $this->name = "Sens Critique"; + $this->uri = "http://www.senscritique.com"; + $this->description = "Sens Critique news"; + $this->update = "2016-07-29"; + + $this->parameters[] = + '[ + { + "name" : "Movies", + "identifier" : "m", + "type": "checkbox" + }, + { + "name" : "Series", + "identifier" : "s", + "type": "checkbox" + }, + { + "name" : "Video Games", + "identifier" : "g", + "type": "checkbox" + }, + { + "name" : "Books", + "identifier" : "b", + "type": "checkbox" + }, + { + "name" : "BD", + "identifier" : "bd", + "type": "checkbox" + }, + { + "name" : "Music", + "identifier" : "mu", + "type": "checkbox" + } + ]'; + } + + public function collectData(array $param) { + if ((isset($param['m']) && $param['m'])) { + $this->collectMoviesData(); + } else if ((isset($param['s']) && $param['s'])) { + $this->collectSeriesData(); + } else if ((isset($param['g']) && $param['g'])) { + $this->collectGamesData(); + } else if ((isset($param['b']) && $param['b'])) { + $this->collectBooksData(); + } else if ((isset($param['bd']) && $param['bd'])) { + $this->collectBDsData(); + } else if ((isset($param['mu']) && $param['mu'])) { + $this->collectMusicsData(); + } else { + $this->returnError('You must choose a category', 400); + } + } + + public function collectMoviesData() { + $html = ''; + $html = $this->file_get_html('http://www.senscritique.com/films/cette-semaine') or $this->returnError('No results for this query.', 404); + $list = $html->find('ul.elpr-list', 0); + + $this->extractDataFromList($list); + } + + public function collectSeriesData() { + $html = ''; + $html = $this->file_get_html('http://www.senscritique.com/series/actualite') or $this->returnError('No results for this query.', 404); + $list = $html->find('ul.elpr-list', 0); + + $this->extractDataFromList($list); + } + + public function collectGamesData() { + $html = ''; + $html = $this->file_get_html('http://www.senscritique.com/jeuxvideo/actualite') or $this->returnError('No results for this query.', 404); + $list = $html->find('ul.elpr-list', 0); + + $this->extractDataFromList($list); + } + + public function collectBooksData() { + $html = ''; + $html = $this->file_get_html('http://www.senscritique.com/livres/actualite') or $this->returnError('No results for this query.', 404); + $list = $html->find('ul.elpr-list', 0); + + $this->extractDataFromList($list); + } + + public function collectBDsData() { + $html = ''; + $html = $this->file_get_html('http://www.senscritique.com/bd/actualite') or $this->returnError('No results for this query.', 404); + $list = $html->find('ul.elpr-list', 0); + + $this->extractDataFromList($list); + } + + public function collectMusicsData() { + $html = ''; + $html = $this->file_get_html('http://www.senscritique.com/musique/actualite') or $this->returnError('No results for this query.', 404); + $list = $html->find('ul.elpr-list', 0); + + $this->extractDataFromList($list); + } + + public function extractDataFromList($list) { + if ($list === null) { + $this->returnError('Cannot extract data from list', 400); + } + + foreach ($list->find('li') as $movie) { + $item = new \Item(); + $item->name = htmlspecialchars_decode($movie->find('.elco-title a', 0)->plaintext, ENT_QUOTES) . ' ' . $movie->find('.elco-date', 0)->plaintext; + $item->title = $movie->find('.elco-title a', 0)->plaintext . ' ' . $movie->find('.elco-date', 0)->plaintext; + $item->content = '' . $movie->find('.elco-original-title', 0)->plaintext . '

' . + $movie->find('.elco-baseline', 0)->plaintext . '
' . + $movie->find('.elco-baseline', 1)->plaintext . '

' . + $movie->find('.elco-description', 0)->plaintext . '

' . + trim($movie->find('.erra-ratings .erra-global', 0)->plaintext) . ' / 10'; + $item->id = $this->getURI() . $movie->find('.elco-title a', 0)->href; + $item->uri = $this->getURI() . $movie->find('.elco-title a', 0)->href; + $this->items[] = $item; + } + } + + public function getName() { + return $this->name; + } + + public function getURI() { + return (trim($this->uri) === "") ? "http://www.senscritique.com" : $this->uri; + } + + public function getCacheDuration(){ + return 0; // 1 hour + } + +} From 9b579c7cd444d7248c9cffb749d3a3eec8e3e06c Mon Sep 17 00:00:00 2001 From: Damien Calesse Date: Sat, 30 Jul 2016 18:19:36 +0200 Subject: [PATCH 2/2] Change Cache Duration Up to 6 hours --- bridges/SensCritiqueBridge.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridges/SensCritiqueBridge.php b/bridges/SensCritiqueBridge.php index c1aaa93e..cfd9e1c9 100644 --- a/bridges/SensCritiqueBridge.php +++ b/bridges/SensCritiqueBridge.php @@ -140,7 +140,7 @@ class SensCritiqueBridge extends BridgeAbstract { } public function getCacheDuration(){ - return 0; // 1 hour + return 21600; // 6 hours } }