diff options
author | Flodur871 <42621369+Flodur871@users.noreply.github.com> | 2021-09-24 22:29:51 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-24 23:29:51 +0100 |
commit | 78d1678ea6b6a685eb05061d2aa283eb3ab157f5 (patch) | |
tree | 505b6ee0f448c1e49c85f8a708bbc0e43fdad789 | |
parent | 942219bd6e0dbf7a49b5d6f288f14fce86d343d1 (diff) |
Added sources argument to the news command (#756)
* Added sources arg to newsapi
* Updated docs
* Added tld check
-rw-r--r-- | gamestonk_terminal/common/newsapi_view.py | 16 | ||||
-rw-r--r-- | gamestonk_terminal/stocks/README.md | 17 | ||||
-rw-r--r-- | gamestonk_terminal/stocks/due_diligence/README.md | 15 | ||||
-rw-r--r-- | gamestonk_terminal/stocks/stocks_controller.py | 13 | ||||
-rwxr-xr-x | website/content/stocks/news/_index.md | 7 |
5 files changed, 47 insertions, 21 deletions
diff --git a/gamestonk_terminal/common/newsapi_view.py b/gamestonk_terminal/common/newsapi_view.py index 64f04b09ee8..a51f2e7daee 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 34a8ed31cab..819fa8617a3 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) + +<img width="770" alt="Captura de ecrã 2021-03-22, às 22 47 42" src="https://user-images.githubusercontent.com/25267873/112070935-b2587a00-8b66-11eb-8dfb-0353fc83311d.png"> + + ## [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 40d9fb36e89..c1b13345d60 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 <a name="news"></a> - -```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. - -<img width="770" alt="Captura de ecrã 2021-03-22, às 22 47 42" src="https://user-images.githubusercontent.com/25267873/112070935-b2587a00-8b66-11eb-8dfb-0353fc83311d.png"> - - ## red <a name="red"></a> ```text diff --git a/gamestonk_terminal/stocks/stocks_controller.py b/gamestonk_terminal/stocks/stocks_controller.py index 4b003a42ebb..7350ad08a29 100644 --- a/gamestonk_terminal/stocks/stocks_controller.py +++ b/gamestonk_terminal/stocks/stocks_controller.py @@ -251,17 +251,30 @@ Market {('CLOSED', 'OPEN')[b_is_stock_market_open()]} 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 0b6bba77315..8eee19690b2 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 ``` |