From f4890b2b6a295629e20d270500f0be9d53bcb4a2 Mon Sep 17 00:00:00 2001 From: Igor Radovanovic <74266147+IgorWounds@users.noreply.github.com> Date: Tue, 30 Jan 2024 10:57:01 +0100 Subject: [PATCH] Remove Ultima provider (#6012) --- .../ultima/openbb_ultima/__init__.py | 27 ----- .../openbb_ultima/models/company_news.py | 95 ---------------- .../openbb_ultima/models/sector_news.py | 103 ------------------ .../ultima/openbb_ultima/utils/helpers.py | 26 ----- 4 files changed, 251 deletions(-) delete mode 100644 openbb_platform/providers/ultima/openbb_ultima/__init__.py delete mode 100644 openbb_platform/providers/ultima/openbb_ultima/models/company_news.py delete mode 100644 openbb_platform/providers/ultima/openbb_ultima/models/sector_news.py delete mode 100644 openbb_platform/providers/ultima/openbb_ultima/utils/helpers.py diff --git a/openbb_platform/providers/ultima/openbb_ultima/__init__.py b/openbb_platform/providers/ultima/openbb_ultima/__init__.py deleted file mode 100644 index 1d7b285740b5..000000000000 --- a/openbb_platform/providers/ultima/openbb_ultima/__init__.py +++ /dev/null @@ -1,27 +0,0 @@ -"""Ultima provider module.""" - -import warnings -from typing import Union - -from openbb_core.provider.abstract.provider import Provider - -ultima_provider: Union[Provider, None] = None - -try: - from openbb_ultima.models.company_news import UltimaCompanyNewsFetcher - from openbb_ultima.models.sector_news import UltimaSectorNewsFetcher - - ultima_provider = Provider( - name="ultima", - website="https://www.ultimainsights.ai/openbb", - description="""Ultima harnesses the power of LLMs to deliver news before it hits the frontpage of Bloomberg.""", - credentials=["api_key"], - fetcher_dict={ - "CompanyNews": UltimaCompanyNewsFetcher, - "SectorNews": UltimaSectorNewsFetcher, - }, - ) -except ImportError: - warnings.warn( - "openbb-ultima is not installed. Please install openbb-ultima to use the Ultima provider." - ) diff --git a/openbb_platform/providers/ultima/openbb_ultima/models/company_news.py b/openbb_platform/providers/ultima/openbb_ultima/models/company_news.py deleted file mode 100644 index 8d28d65cdae8..000000000000 --- a/openbb_platform/providers/ultima/openbb_ultima/models/company_news.py +++ /dev/null @@ -1,95 +0,0 @@ -"""Ultima Company News Model.""" - -from datetime import datetime -from typing import Any, Dict, List, Optional - -from openbb_core.provider.abstract.fetcher import Fetcher -from openbb_core.provider.standard_models.company_news import ( - CompanyNewsData, - CompanyNewsQueryParams, -) -from openbb_ultima.utils.helpers import get_data -from pydantic import Field - - -class UltimaCompanyNewsQueryParams(CompanyNewsQueryParams): - """Ultima Company News Query. - - Source: https://api.ultimainsights.ai/v1/api-docs#/default/get_v1_getOpenBBProInsights__tickers_ - """ - - __alias_dict__ = { - "symbols": "tickers", - } - - -class UltimaCompanyNewsData(CompanyNewsData): - """Ultima Company News Data.""" - - __alias_dict__ = { - "symbols": "ticker", - "date": "publishedDate", - "text": "summary", - "title": "headline", - } - - publisher: str = Field(description="Publisher of the news.") - risk_category: str = Field(description="Risk category of the news.") - - -class UltimaCompanyNewsFetcher( - Fetcher[ - UltimaCompanyNewsQueryParams, - List[UltimaCompanyNewsData], - ] -): - """Transform the query, extract and transform the data from the Ultima endpoints.""" - - @staticmethod - def transform_query(params: Dict[str, Any]) -> UltimaCompanyNewsQueryParams: - """Transform query.""" - return UltimaCompanyNewsQueryParams(**params) - - @staticmethod - def extract_data( - query: UltimaCompanyNewsQueryParams, - credentials: Optional[Dict[str, str]], - **kwargs: Any, - ) -> List[Dict]: - """Extract data from Ultima Insights API.""" - token = credentials.get("ultima_api_key") if credentials else "" - kwargs["auth"] = token - - base_url = "https://api.ultimainsights.ai/v1/getOpenBBProInsights" - - querystring = str(query).split("=")[1].split("'")[1].replace(" ", "") - - data = [] - url = f"{base_url}/{querystring}" - response = get_data(url, **kwargs) - data.extend(response) - - return data - - @staticmethod - def transform_data( - query: UltimaCompanyNewsQueryParams, - data: List[Dict], - **kwargs: Any, - ) -> List[UltimaCompanyNewsData]: - """Transform data.""" - results = [] - for ele in data: - for key in ["8k_filings", "articles", "industry_summary"]: - for item in ele[key]: - # manual assignment required for Pydantic to work - item["symbols"] = ele["ticker"] - item["date"] = datetime.strptime( - item["publishedDate"], "%Y-%m-%d %H:%M:%S" - ) - item["title"] = item["headline"] - item["url"] = item["url"] - item["publisher"] = item["publisher"] - item["risk_category"] = item["riskCategory"] - results.append(UltimaCompanyNewsData.model_validate(item)) - return results diff --git a/openbb_platform/providers/ultima/openbb_ultima/models/sector_news.py b/openbb_platform/providers/ultima/openbb_ultima/models/sector_news.py deleted file mode 100644 index 78c5c23b2480..000000000000 --- a/openbb_platform/providers/ultima/openbb_ultima/models/sector_news.py +++ /dev/null @@ -1,103 +0,0 @@ -"""Ultima Sector News Model.""" - -from datetime import datetime -from typing import Any, Dict, List, Optional - -from openbb_core.provider.abstract.fetcher import Fetcher -from openbb_core.provider.standard_models.sector_news import ( - SectorNewsData, - SectorNewsQueryParams, -) -from openbb_ultima.utils.helpers import get_data -from pydantic import Field - - -class UltimaSectorNewsQueryParams(SectorNewsQueryParams): - """Ultima Sector News Query. - - Source: https://api.ultimainsights.ai/v1/api-docs#/default/get_v1_getOpenBBProInsights__tickers_ - """ - - __alias_dict__ = { - "symbols": "sectors", - } - - -class UltimaSectorNewsData(SectorNewsData): - """Ultima Sector News Data.""" - - __alias_dict__ = { - "symbols": "ticker", - "date": "publishedDate", - "text": "summary", - "title": "headline", - } - - publisher: str = Field(description="Publisher of the news.") - risk_category: str = Field(description="Risk category of the news.") - - -class UltimaSectorNewsFetcher( - Fetcher[ - UltimaSectorNewsQueryParams, - List[UltimaSectorNewsData], - ] -): - """Transform the query, extract and transform the data from the Ultima endpoints.""" - - @staticmethod - def transform_query(params: Dict[str, Any]) -> UltimaSectorNewsQueryParams: - """Transform query.""" - return UltimaSectorNewsQueryParams(**params) - - @staticmethod - def extract_data( - query: UltimaSectorNewsQueryParams, - credentials: Optional[Dict[str, str]], - **kwargs: Any, - ) -> List[Dict]: - """Extract data from Ultima Insights API.""" - token = credentials.get("ultima_api_key") if credentials else "" - kwargs["auth"] = token - - base_url = "https://api.ultimainsights.ai/v1/getCompaniesForSectors" - pro_base_url = "https://api.ultimainsights.ai/v1/getOpenBBProInsights" - - querystring = str(query).split("=")[1].split("'")[1] - - tickers = [] - url = f"{base_url}/{querystring}" - response = get_data(url, **kwargs) - tickers.extend(response) - - querystring = ",".join(tickers) - - data = [] - url = f"{pro_base_url}/{querystring}" - response = get_data(url, **kwargs) - data.extend(response) - - return data - - @staticmethod - def transform_data( - query: UltimaSectorNewsQueryParams, - data: List[Dict], - **kwargs: Any, - ) -> List[UltimaSectorNewsData]: - """Transform data.""" - results = [] - for ele in data: - for key in ["8k_filings", "articles", "industry_summary"]: - for item in ele[key]: - # manual assignment required for Pydantic to work - item["symbols"] = ele["ticker"] - item["date"] = datetime.strptime( - item["publishedDate"], "%Y-%m-%d %H:%M:%S" - ) - item["title"] = item["headline"] - item["url"] = item["url"] - item["publisher"] = item["publisher"] - item["risk_category"] = item["riskCategory"] - results.append(UltimaSectorNewsData.model_validate(item)) - return results diff --git a/openbb_platform/providers/ultima/openbb_ultima/utils/helpers.py b/openbb_platform/providers/ultima/openbb_ultima/utils/helpers.py deleted file mode 100644 index 1fe2c3dc64e8..000000000000 --- a/openbb_platform/providers/ultima/openbb_ultima/utils/helpers.py +++ /dev/null @@ -1,26 +0,0 @@ -"""Ultima Helpers.""" - -from typing import Any, Dict - -from openbb_core.provider import helpers - - -def get_data(url: str, **kwargs: Any) -> Dict: - """Do an API request to Ultima and return the data.""" - auth = kwargs.pop("auth", "") - if auth is None or len(auth) == 0: - raise RuntimeError("Ultima API key is required.") - if "Bearer" not in auth: - auth = f"Bearer {auth}" - result = helpers.make_request( - url, - timeout=10, - headers={"accept": "application/json", "Authorization": auth}, - **kwargs, - ) - if result.status_code != 200: - data = result.json() - message = data.get("message") - raise RuntimeError(f"Error in Ultima request -> {message}") - - return result.json()