From a07874d46839acf387895b585cbea7990e0e6fc7 Mon Sep 17 00:00:00 2001 From: Matt DeMoss Date: Fri, 12 Jan 2018 07:08:15 -0500 Subject: [PATCH] Initial commit for Bloomberg bridge with top stories and search (#607) * initial commit for Bloomberg bridge with top stories and search --- bridges/BloombergBridge.php | 65 +++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 bridges/BloombergBridge.php diff --git a/bridges/BloombergBridge.php b/bridges/BloombergBridge.php new file mode 100644 index 0000000..8aff0ec --- /dev/null +++ b/bridges/BloombergBridge.php @@ -0,0 +1,65 @@ + array(), + 'From Search' => array( + 'q' => array( + 'name' => 'Keyword', + 'required' => true + ) + ) + ); + + public function getName() + { + switch($this->queriedContext) { + case 'Trending Stories': + return self::NAME . ' Trending Stories'; + case 'From Search': + if (!is_null($this->getInput('q'))) { + return self::NAME . ' Search : ' . $this->getInput('q'); + } + break; + } + + return parent::getName(); + } + + public function collectData() + { + switch($this->queriedContext) { + case 'Trending Stories': // Get list of top new
s from the front page. + $html = getSimpleHTMLDOMCached($this->getURI(), 300); + $stories = $html->find('ul.top-news-v3__stories article.top-news-v3-story'); + break; + case 'From Search': // Get list of
elements from search. + $html = getSimpleHTMLDOMCached( + $this->getURI() . + 'search?sort=time:desc&page=1&query=' . + urlencode($this->getInput('q')), 300 + ); + $stories = $html->find('div.search-result-items article.search-result-story'); + break; + } + foreach ($stories as $element) { + $item['uri'] = $element->find('h1 a', 0)->href; + if (preg_match('#^https://#i', $item['uri']) !== 1) { + $item['uri'] = $this->getURI() . $item['uri']; + } + $articleHtml = getSimpleHTMLDOMCached($item['uri']); + if (!$articleHtml) { + continue; + } + $item['title'] = $element->find('h1 a', 0)->plaintext; + $item['timestamp'] = strtotime($articleHtml->find('meta[name=iso-8601-publish-date],meta[name=date]', 0)->content); + $item['content'] = $articleHtml->find('meta[name=description]', 0)->content; + $this->items[] = $item; + } + } +}