diff --git a/gamestonk_terminal/common/newsapi_view.py b/gamestonk_terminal/common/newsapi_view.py index 64f04b09ee8c..a51f2e7daee0 100644 --- a/gamestonk_terminal/common/newsapi_view.py +++ b/gamestonk_terminal/common/newsapi_view.py @@ -11,6 +11,7 @@ def news( num: int, s_from: str, show_newest: bool, + sources: str, ): """Display news for a given title. [Source: NewsAPI] @@ -24,14 +25,19 @@ def news( date to start searching articles from formatted YYYY-MM-DD show_newest: bool flag to show newest articles first + sources: str + sources to exclusively show news from """ - # TODO: Add argument to specify news source being used - - response = requests.get( - f"https://newsapi.org/v2/everything?q={term}&from={s_from}" - f"&sortBy=publishedAt&language=en&apiKey={cfg.API_NEWS_TOKEN}", + link = ( + f"https://newsapi.org/v2/everything?q={term}&from={s_from}&sortBy=publishedAt&language=en" + f"&apiKey={cfg.API_NEWS_TOKEN}" ) + if sources: + link += f"&domains={sources}" + + response = requests.get(link) + # Check that the API response was successful if response.status_code == 426: print(f"Error in request: {response.json()['message']}", "\n") diff --git a/gamestonk_terminal/stocks/README.md b/gamestonk_terminal/stocks/README.md index 34a8ed31cab1..819fa8617a39 100644 --- a/gamestonk_terminal/stocks/README.md +++ b/gamestonk_terminal/stocks/README.md @@ -4,6 +4,7 @@ * [Load](#Load) * [Quote](#Quote) * [Candle](#Candle) + * [News](#News) * [Discover Stocks](#Discover-Stocks-) * [Behavioural Analysis](#Behavioural-Analysis-) * [Research](#Research-) @@ -49,6 +50,22 @@ Visualize candles historical data, with support and resistance bars, and moving ![nio](https://user-images.githubusercontent.com/25267873/111053397-4d609e00-845b-11eb-9c94-89b8892a8e81.png) +#### News + +```text +news [-n N_NUM] [-d N_START_DATE] [-o] [-s N_SOURCES [N_SOURCES ...]] +``` + +Prints latest news about company, including date, title and web link. [Source: News API] + +* -n : Number of latest news being printed. Default 5. +* -d : The starting date (format YYYY-MM-DD) to search articles from. +* -o : Show oldest articles first. +* -s : Show news only from the sources specified (e.g bbc yahoo.com) + +Captura de ecrã 2021-03-22, às 22 47 42 + + ## [Discover Stocks »»](discovery/README.md) Command|Description|Source diff --git a/gamestonk_terminal/stocks/due_diligence/README.md b/gamestonk_terminal/stocks/due_diligence/README.md index 40d9fb36e89c..c1b13345d607 100644 --- a/gamestonk_terminal/stocks/due_diligence/README.md +++ b/gamestonk_terminal/stocks/due_diligence/README.md @@ -2,8 +2,6 @@ This menu aims to help in due-diligence of a pre-loaded stock, and the usage of the following commands along with an example will be exploited below. -* [news](#news) - * latest news of the company [News API] * [red](#red) * gets due diligence from another user's post [Reddit] * [analyst](#analyst) @@ -39,19 +37,6 @@ This menu aims to help in due-diligence of a pre-loaded stock, and the usage of * [customer](#customer) * list of customers [csimarket] -## news - -```text -news [-n N_NUM] -``` - -Prints latest news about company, including date, title and web link. [Source: News API] - -* -n : Number of latest news being printed. Default 10. - -Captura de ecrã 2021-03-22, às 22 47 42 - - ## red ```text diff --git a/gamestonk_terminal/stocks/stocks_controller.py b/gamestonk_terminal/stocks/stocks_controller.py index 4b003a42ebb5..7350ad08a290 100644 --- a/gamestonk_terminal/stocks/stocks_controller.py +++ b/gamestonk_terminal/stocks/stocks_controller.py @@ -251,17 +251,30 @@ def call_news(self, other_args: List[str]): default=True, help="Show oldest articles first", ) + parser.add_argument( + "-s", + "--sources", + default=[], + nargs="+", + help="Show news only from the sources specified (e.g bbc yahoo.com)", + ) try: ns_parser = parse_known_args_and_warn(parser, other_args) if not ns_parser: return + sources = ns_parser.sources + for idx, source in enumerate(sources): + if source.find(".") == -1: + sources[idx] += ".com" + newsapi_view.news( term=self.ticker, num=ns_parser.n_num, s_from=ns_parser.n_start_date.strftime("%Y-%m-%d"), show_newest=ns_parser.n_oldest, + sources=",".join(sources), ) except Exception as e: diff --git a/website/content/stocks/news/_index.md b/website/content/stocks/news/_index.md index 0b6bba773153..8eee19690b2f 100755 --- a/website/content/stocks/news/_index.md +++ b/website/content/stocks/news/_index.md @@ -1,5 +1,5 @@ ``` -usage: news [-n N_NUM] [-h] +usage: news [-n N_NUM] [-d N_START_DATE] [-o] [-s N_SOURCES [N_SOURCES ...]] [-h] ``` Prints latest news about company, including date, title and web link. [Source: News API] @@ -8,5 +8,10 @@ Prints latest news about company, including date, title and web link. [Source: N optional arguments: -n N_NUM, --num N_NUM Number of latest news being printed. + -d N_START_DATE, --date N_START_DATE + The starting date (format YYYY-MM-DD) to search articles from + -o, --oldest Show oldest articles first + -s N_SOURCES [N_SOURCES ...], --sources N_SOURCES [N_SOURCES ...] + Show news only from the sources specified (e.g bbc yahoo.com) -h, --help show this help message ```