From c2559ff71fb3ffb81810152d46071129a2e8a4d9 Mon Sep 17 00:00:00 2001 From: Kirill Kotikov Date: Mon, 16 Mar 2020 19:25:28 +0300 Subject: [PATCH] Add sdfsf --- bridges/GithubTrendingBridge.php | 66 ++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 bridges/GithubTrendingBridge.php diff --git a/bridges/GithubTrendingBridge.php b/bridges/GithubTrendingBridge.php new file mode 100644 index 00000000..f788887d --- /dev/null +++ b/bridges/GithubTrendingBridge.php @@ -0,0 +1,66 @@ + array( + 'language' => array( + 'name' => 'Programming language', + 'required' => true + ) + ), + 'global' => array( + 'date_range' => array( + 'name' => 'Date range', + 'type' => 'list', + 'required' => false, + 'values' => array( + 'Today' => 'today', + 'Weekly' => 'weekly', + 'Monthly' => 'monthly', + ), + 'defaultValue' => 'today' + ) + ) + + ); + + public function collectData(){ + $params = array('since' => urlencode($this->getInput('date_range'))); + $url = self::URI . '/' . $this->getInput('language') . '?' . http_build_query($params); + + $html = getSimpleHTMLDOM($url) + or returnServerError('Error while downloading the website content'); + + foreach($html->find('.Box-row') as $element) { + $item = array(); + + // URI + $item['uri'] = substr(self::URI, 0, -1) . $element->find('h1 a', 0)->href; + + // Title + $item['title'] = str_replace(' ', '', trim(strip_tags($element->find('h1 a', 0)->plaintext))); + + // Description + $item['description'] = trim(strip_tags($element->find('p.text-gray', 0)->innertext)); + + // Time + $item['timestamp'] = time(); + + // TODO: Proxy? + $this->items[] = $item; + } + } + + public function getName(){ + if(!is_null($this->getInput('language'))) { + return self::NAME . ' - ' . $this->getInput('language'); + } + + return parent::getName(); + } +}