Files
OpenBB/openbb_terminal/common/feedparser_view.py
DidierRLopes 8eed33b62f News from feedparser + Binance API key check fix (#2192)
* fix binance controller API key

* add news to main menu

* feedparser

* trying to help

* requirements for didier

* one test

* fix suggestion by @rpydaneogrendim on Twitter

* fix tests

* trying to help again?

* test

Co-authored-by: james <jmaslek11@gmail.com>
2022-07-29 22:13:45 +01:00

49 lines
1.2 KiB
Python

""" News View """
__docformat__ = "numpy"
import logging
import os
from openbb_terminal.decorators import log_start_end
from openbb_terminal.helper_funcs import export_data
from openbb_terminal.rich_config import console
from openbb_terminal.common import feedparser_model
logger = logging.getLogger(__name__)
@log_start_end(log=logger)
def display_news(
term: str,
sources: str = "",
limit: int = 5,
export: str = "",
):
"""Display news for a given term and source. [Source: Feedparser]
Parameters
----------
term : str
term to search on the news articles
sources : str
sources to exclusively show news from
limit : int
number of articles to display
export : str
Export dataframe data to csv,json,xlsx file
"""
articles = feedparser_model.get_news(term, sources)
console.print()
for _, row in articles.head(limit).iterrows():
console.print(f"> {row['published']} - {row['title']}")
console.print(row["link"] + "\n")
console.print()
export_data(
export,
os.path.dirname(os.path.abspath(__file__)),
f"news_{'_'.join(term)}_{'_'.join(sources)}",
articles,
)