mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-30 14:02:06 +00:00
Added sources argument to the news command (#756)
* Added sources arg to newsapi * Updated docs * Added tld check
This commit is contained in:
@@ -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")
|
||||
|
||||
17
gamestonk_terminal/stocks/README.md
vendored
17
gamestonk_terminal/stocks/README.md
vendored
@@ -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
|
||||

|
||||
|
||||
|
||||
#### 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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
7
website/content/stocks/news/_index.md
vendored
7
website/content/stocks/news/_index.md
vendored
@@ -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
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user