From 684558e276af9af6858adfa6d9d5d0e5bf964bb6 Mon Sep 17 00:00:00 2001 From: Nemo Date: Mon, 18 Mar 2019 01:10:21 +0530 Subject: [PATCH] [StockFilingsBridge] Add new bridge (#1011) --- bridges/StockFilingsBridge.php | 80 ++++++++++++++++++++++++++++++++++ lib/FeedItem.php | 2 +- 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 bridges/StockFilingsBridge.php diff --git a/bridges/StockFilingsBridge.php b/bridges/StockFilingsBridge.php new file mode 100644 index 00000000..f774244a --- /dev/null +++ b/bridges/StockFilingsBridge.php @@ -0,0 +1,80 @@ + array( + 'name' => 'cik', + 'required' => true, + 'exampleValue' => 'AMD', + // https://stackoverflow.com/a/12827734 + 'pattern' => '[A-Za-z0-9]+', + ), + )); + + public function getIcon() { + return 'https://www.sec.gov/favicon.ico'; + } + + /** + * Generates search URL + */ + private function getSearchUrl() { + return self::SEARCH_URL . $this->getInput('ticker'); + } + + /** + * Returns the Company Name + */ + private function getRssFeed($html) { + $links = $html->find('#contentDiv a'); + + foreach ($links as $link) { + $href = $link->href; + + if (substr($href, 0, 4) !== 'http') { + $href = self::WEBSITE_ROOT . $href; + } + parse_str(html_entity_decode(parse_url($href, PHP_URL_QUERY)), $query); + + if (isset($query['output']) and ($query['output'] == 'atom')) { + return $href; + } + } + + return false; + } + + /** + * Return \simple_html_dom object + * for the entire html of the product page + */ + private function getHtml() { + $uri = $this->getSearchUrl(); + + return getSimpleHTMLDOM($uri) ?: returnServerError('Could not request SEC.'); + } + + /** + * Scrape the SEC Stock Filings RSS Feed URL + * and redirect there + */ + public function collectData() { + $html = $this->getHtml(); + $rssFeedUrl = $this->getRssFeed($html); + + if ($rssFeedUrl) { + parent::collectExpandableDatas($rssFeedUrl); + } else { + returnClientError('Could not find RSS Feed URL. Are you sure you used a valid CIK?'); + } + } +} diff --git a/lib/FeedItem.php b/lib/FeedItem.php index aedf615a..de707f8b 100644 --- a/lib/FeedItem.php +++ b/lib/FeedItem.php @@ -76,7 +76,7 @@ class FeedItem { * $item['uri'] = 'https://www.github.com/rss-bridge/rss-bridge/'; * $item['title'] = 'Title'; * $item['timestamp'] = strtotime('now'); - * $item['autor'] = 'Unknown author'; + * $item['author'] = 'Unknown author'; * $item['content'] = 'Hello World!'; * $item['enclosures'] = array('https://github.com/favicon.ico'); * $item['categories'] = array('php', 'rss-bridge', 'awesome');