diff options
author | James Maslek <jmaslek11@gmail.com> | 2024-02-29 12:45:19 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-29 12:45:19 -0500 |
commit | b458d2f4ba9ddaca7cdd1dc54ce29bbe1a0ec218 (patch) | |
tree | dd5af9e0890c66cac7d77314128441d7752cd544 /openbb_terminal | |
parent | 1d70c877ff9317ed95a333ab1f3d9f3112ca4149 (diff) |
More v3 removals (#6141)
* remove ultima + althub
* move twitter keys
* economy kill bigmac + remove eval + plot+ stored data
* am losing track
* oanda is next
* brokers now
* fix sdk in case anyone wants it
* missed an sdk endpoint
* spec file
* small edits for installer
* stop the int tests on these
* always be fixin bugs
* some more removals
Diffstat (limited to 'openbb_terminal')
52 files changed, 45 insertions, 6374 deletions
diff --git a/openbb_terminal/common/ultima_newsmonitor_model.py b/openbb_terminal/common/ultima_newsmonitor_model.py deleted file mode 100644 index 0fb041dda16..00000000000 --- a/openbb_terminal/common/ultima_newsmonitor_model.py +++ /dev/null @@ -1,240 +0,0 @@ -""" Ultima News Monitor Model """ - -__docformat__ = "numpy" - -import logging -import os -from urllib.parse import quote - -import certifi -import pandas as pd - -from openbb_terminal.core.session.current_user import get_current_user -from openbb_terminal.decorators import log_start_end - -# from openbb_terminal.decorators import check_api_key -from openbb_terminal.helper_funcs import request -from openbb_terminal.rich_config import console - -logger = logging.getLogger(__name__) - - -ULTIMA_BASE_URL = "https://api.ultimainsights.ai/v1" -NO_API_KEY = "REPLACE_ME" - - -@log_start_end(log=logger) -# @check_api_key(["API_ULTIMA_KEY"]) -def get_news(term: str = "", sort: str = "articlePublishedDate") -> pd.DataFrame: - """Get news for a given term and source. [Source: Ultima Insights News Monitor] - - Parameters - ---------- - term : str - term to search on the news articles - sort: str - the column to sort by - - Returns - ------- - articles: pd.DataFrame - term to search on the news articles - - Examples - -------- - >>> from openbb_terminal.sdk import openbb - >>> openbb.news() - """ - # Necessary for installer so that it can locate the correct certificates for - # API calls and https - # https://stackoverflow.com/questions/27835619/urllib-and-ssl-certificate-verify-failed-error/73270162#73270162 - os.environ["REQUESTS_CA_BUNDLE"] = certifi.where() - os.environ["SSL_CERT_FILE"] = certifi.where() - - current_user = get_current_user() - if current_user.credentials.API_ULTIMA_KEY == NO_API_KEY: - auth_header = None - else: - auth_header = { - "Authorization": f"Bearer {current_user.credentials.API_ULTIMA_KEY}" - } - - have_data = False - limit = 0 - - while not have_data: - if term: - term = quote(term) - term = term.upper() - term = term.strip() - if term in supported_terms(): - if auth_header: - data = request( - f"{ULTIMA_BASE_URL}/getNewsArticles/{term}", headers=auth_header - ) - else: - data = request(f"{ULTIMA_BASE_URL}/getNewsArticles/{term}") - else: - console.print( - "[red]Ticker not supported. Unable to retrieve data\n[/red]" - ) - return pd.DataFrame() - else: - console.print("[red]No term specified. Unable to retrieve data\n[/red]") - return pd.DataFrame() - - if ( - hasattr(data, "status") and data.status_code == 200 - ): # Checking if data has status attribute and if data request succeeded - if data.content: - have_data = True - elif limit == 60: # Breaking if 60 successful requests return no data - console.print("[red]Timeout occurred. Please try again\n[/red]") - break - limit = limit + 1 - - elif ( - hasattr(data, "status") and data.status_code == 429 - ): # If data request failed - console.print( - "[red]Too many requests. Please get an API Key from https://www.ultimainsights.ai/[/red]" - ) - break - elif ( - hasattr(data, "status") and data.status_code != 200 - ): # If data request failed - console.print("[red]Status code not 200. Unable to retrieve data\n[/red]") - break - else: - # console.print("[red]Could not retrieve data\n[/red]") - break - if not data.json(): - return pd.DataFrame() - df = pd.DataFrame( - data.json(), - columns=[ - "articleHeadline", - "articleURL", - "articlePublishedDate", - "riskCategory", - "riskElaboratedDescription", - "relevancyScore", - ], - ) - df = df[df["relevancyScore"] < 5] - df = df[df["relevancyScore"] > 3.5] - df["riskElaboratedDescription"] = df["riskElaboratedDescription"].str.replace( - "\n", "" - ) - df["riskElaboratedDescription"] = df["riskElaboratedDescription"].str.replace( - "\n", "" - ) - df["articlePublishedDate"] = pd.to_datetime(df["articlePublishedDate"]) - df = df.sort_values(by=[sort], ascending=False) - return df - - -@log_start_end(log=logger) -# @check_api_key(["API_ULTIMA_KEY"]) -def supported_terms() -> list: - """Get supported terms for news. [Source: Ultima] - - Returns - ------- - terms: list - list of supported terms (tickers) - - """ - - # Necessary for installer so that it can locate the correct certificates for - # API calls and https - # https://stackoverflow.com/questions/27835619/urllib-and-ssl-certificate-verify-failed-error/73270162#73270162 - os.environ["REQUESTS_CA_BUNDLE"] = certifi.where() - os.environ["SSL_CERT_FILE"] = certifi.where() - data = request(f"{ULTIMA_BASE_URL}/supportedTickers") - return list(data.json()) - - -@log_start_end(log=logger) -def get_company_info(ticker: str) -> dict: - """Get company info for a given ticker. [Source: Ultima Insights] - - Parameters - ---------- - ticker : str - ticker to search for company info - - Returns - ------- - company_info: dict - dictionary of company info - """ - - # Necessary for installer so that it can locate the correct certificates for - # API calls and https - # https://stackoverflow.com/questions/27835619/urllib-and-ssl-certificate-verify-failed-error/73270162#73270162 - os.environ["REQUESTS_CA_BUNDLE"] = certifi.where() - os.environ["SSL_CERT_FILE"] = certifi.where() - - if ticker in supported_terms(): - data = request(f"{ULTIMA_BASE_URL}/getCompanyInfo/{ticker}") - return data.json() - console.print("[red]Ticker not supported. Unable to retrieve data\n[/red]") - return {} - - -@log_start_end(log=logger) -def get_top_headlines(ticker: str) -> dict: - """Get top headlines for a given ticker. [Source: Ultima Insights] - - Parameters - ---------- - ticker : str - ticker to get top headlines for - - Returns - ------- - top_headlines: dict - dictionary of top headlines - """ - - # Necessary for installer so that it can locate the correct certificates for - # API calls and https - # https://stackoverflow.com/questions/27835619/urllib-and-ssl-certificate-verify-failed-error/73270162#73270162 - os.environ["REQUESTS_CA_BUNDLE"] = certifi.where() - os.environ["SSL_CERT_FILE"] = certifi.where() - - current_user = get_current_user() - if current_user.credentials.API_ULTIMA_KEY == NO_API_KEY: - auth_header = None - else: - auth_header = { - "Authorization": f"Bearer {current_user.credentials.API_ULTIMA_KEY}" - } - - if ticker in supported_terms(): - if auth_header: - data = request( - f"{ULTIMA_BASE_URL}/getTopHeadlines/{ticker}", headers=auth_header - ) - else: - data = request(f"{ULTIMA_BASE_URL}/getTopHeadlines/{ticker}") - if ( - hasattr(data, "status") and data.status_code == 429 - ): # If data request failed - console.print( - "[red]Too many requests. Please get an API Key from https://www.ultimainsights.ai/[/red]" - ) - return {} - if ( - hasattr(data, "status") and data.status_code != 200 - ): # If data request failed - console.print("[red]Status code not 200. Unable to retrieve data\n[/red]") - return {} - json = data.json() - if "message" in json: - console.print(f"[red]{json['message']}[/red]") - return {} - return json - console.print("[red]Ticker not supported. Unable to retrieve data\n[/red]") - return {} diff --git a/openbb_terminal/common/ultima_newsmonitor_view.py b/openbb_terminal/common/ultima_newsmonitor_view.py deleted file mode 100644 index 3e01dd14a53..00000000000 --- a/openbb_terminal/common/ultima_newsmonitor_view.py +++ /dev/null @@ -1,130 +0,0 @@ -""" News View """ - -__docformat__ = "numpy" - -import datetime as dt -import logging -import os -from typing import Optional - -import pandas as pd - -from openbb_terminal.common import feedparser_model, ultima_newsmonitor_model -from openbb_terminal.decorators import log_start_end -from openbb_terminal.helper_funcs import export_data -from openbb_terminal.rich_config import console - -logger = logging.getLogger(__name__) - - -@log_start_end(log=logger) -def display_news( - term: str, - sources: str = "", - limit: int = 5, - export: str = "", - sheet_name: Optional[str] = None, - sort: str = "articlePublishedDate", -): - """Plots news for a given term and source. [Source: Ultima Insights] - - 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 - sort: str - the column to sort by - """ - console.print() - if term not in ultima_newsmonitor_model.supported_terms(): - console.print(f"[red]Unsupported ticker: {term}[/red]") - return - company_info = ultima_newsmonitor_model.get_company_info(term) - company_name = company_info.get("companyShortName", term) - # TODO: calling them all together does not work with feedparser - bbg = feedparser_model.get_news( - company_name, sources="bloomberg", sort="published", display_message=False - ) - wsj = feedparser_model.get_news( - company_name, sources="wsj", sort="published", display_message=False - ) - reuters = feedparser_model.get_news( - company_name, sources="reuters", sort="published", display_message=False - ) - cnbc = feedparser_model.get_news( - company_name, sources="cnbc", sort="published", display_message=False - ) - breaking_news = pd.concat([bbg, wsj, reuters, cnbc]) - if len(breaking_news) > 0: - breaking_news = breaking_news.sort_values(by="Date", ascending=False) - breaking_news["DateNorm"] = ( - pd.to_datetime(breaking_news["Date"]).dt.tz_convert(None).dt.normalize() - ) - today = pd.to_datetime("today").normalize() - breaking_news = breaking_news[breaking_news["DateNorm"] == today] - if len(breaking_news) > 0: - console.print( - "Uncategorized Breaking News (Bloomberg, Reuters, WSJ, CNBC):" - ) - for _, row in breaking_news.head(limit).iterrows(): - console.print(f"> {row['Date']} - {row['Description']}") - console.print(row["URL"] + "\n") - console.print("------------------------") - - top_headlines = ultima_newsmonitor_model.get_top_headlines(term) - if "summary" in top_headlines: - top_headlines = top_headlines["summary"] - else: - return - if "Ultima Insights was unable to identify" in top_headlines: - console.print( - f"[red]Most Relevant Articles for {term} - {dt.datetime.now().strftime('%Y-%m-%d')}\n{top_headlines}[/red]" - ) - else: - split = top_headlines.split("\n") - header = split[0] - if "Most" not in header: - header = f'Most Relevant Articles for {term} - {dt.datetime.now().strftime("%Y-%m-%d")}' - console.print(f"[purple][bold]{header}[/bold][/purple]\n") - for idx, row in enumerate(split[1:]): - if len(row) > 0: - inner_split = row.split(" - ") - risk = inner_split[0] - description = " - ".join(inner_split[1:]) - console.print(f"[green]{risk}[/green] (\x1B[3m{description}\x1B[0m)") - if idx < len(split[1:]) - 1: - console.print() - console.print("------------------------") - articles = ultima_newsmonitor_model.get_news(term, sort) - articles = articles.head(limit).sort_values(by="relevancyScore", ascending=False) - console.print(f"\n[purple][bold]News for {company_name}:[/bold][/purple]\n\n") - for _, row in articles.iterrows(): - console.print( - f"> {row['articlePublishedDate']} - {row['articleHeadline']}\n" - f"[purple]Relevancy score: {round(row['relevancyScore'], 2) if row['relevancyScore'] < 5 else 5}" - f"/5 Stars[/purple]\n[green]{row['riskCategory']}[/green] " - f"(\x1B[3m{row['riskElaboratedDescription']}\x1B[0m)" - ) - console.print(f"Read more: {row['articleURL']}\n") - # console.print("[purple]To report any issues, please visit https://beta.ultimainsights.ai/my-account/support[/purple]\n") - console.print() - - export_data( - export, - os.path.dirname(os.path.abspath(__file__)), - f"news_{'_'.join(term)}_{'_'.join(sources)}", - articles, - sheet_name, - ) - - -@log_start_end(log=logger) -def supported_terms() -> list: - """Returns supported terms for news""" - return ultima_newsmonitor_model.supported_terms() diff --git a/openbb_terminal/core/sdk/controllers/__init__.py b/openbb_terminal/core/sdk/controllers/__init__.py index 893575893b1..fb33aa31e92 100644 --- a/openbb_terminal/core/sdk/controllers/__init__.py +++ b/openbb_terminal/core/sdk/controllers/__init__.py @@ -5,6 +5,5 @@ from .alt_sdk_controller import AltController from .crypto_sdk_controller import CryptoController from .etf_sdk_controller import EtfController -from .forex_sdk_controller import ForexController from .portfolio_sdk_controller import PortfolioController from .stocks_sdk_controller import StocksController diff --git a/openbb_terminal/core/sdk/controllers/forex_sdk_controller.py b/openbb_terminal/core/sdk/controllers/forex_sdk_controller.py deleted file mode 100644 index ab98923cfa4..00000000000 --- a/openbb_terminal/core/sdk/controllers/forex_sdk_controller.py +++ /dev/null @@ -1,54 +0,0 @@ -# ######### THIS FILE IS AUTO GENERATED - ANY CHANGES WILL BE VOID ######### # -# flake8: noqa -# pylint: disable=C0301,R0902,R0903 -from openbb_terminal.core.sdk.models import forex_sdk_model as model - - -class ForexController(model.ForexRoot): - """Forex Module. - - Submodules: - `oanda`: Oanda Module - - Attributes: - `candle`: Show candle plot for fx data.\n - `fwd`: Gets forward rates from fxempire\n - `get_currency_list`: Load AV currency codes from a local file.\n - `load`: Load forex for two given symbols.\n - `quote`: Get forex quote.\n - """ - - @property - def oanda(self): - """Forex Oanda Submodule - - Attributes: - `calendar`: Request data of significant event |