diff options
author | Danglewood <85772166+deeleeramone@users.noreply.github.com> | 2024-05-16 13:00:37 -0700 |
---|---|---|
committer | Danglewood <85772166+deeleeramone@users.noreply.github.com> | 2024-05-16 13:00:37 -0700 |
commit | 2d297c9cfc02186b60a252a627104dc73c9bf6b8 (patch) | |
tree | 48f74a9d11fb921b9a57098fb3ee07fd10b074d8 | |
parent | 4c4f57fa78879b0700affc5552f8dd2145608d82 (diff) |
TO-DOs done
4 files changed, 65 insertions, 28 deletions
diff --git a/openbb_platform/openbb/assets/reference.json b/openbb_platform/openbb/assets/reference.json index c4fd0fe8059..5449acc33c9 100644 --- a/openbb_platform/openbb/assets/reference.json +++ b/openbb_platform/openbb/assets/reference.json @@ -30534,7 +30534,7 @@ { "name": "business_relevance_greater_than", "type": "float", - "description": "News stories will have a business relevance score more than this value. Unsupported for yahoo source.", + "description": "News stories will have a business relevance score more than this value. Unsupported for yahoo source. Value is a decimal between 0 and 1.", "default": null, "optional": true, "choices": null @@ -30542,7 +30542,7 @@ { "name": "business_relevance_less_than", "type": "float", - "description": "News stories will have a business relevance score less than this value. Unsupported for yahoo source.", + "description": "News stories will have a business relevance score less than this value. Unsupported for yahoo source. Value is a decimal between 0 and 1.", "default": null, "optional": true, "choices": null @@ -31075,7 +31075,7 @@ { "name": "business_relevance_greater_than", "type": "float", - "description": "News stories will have a business relevance score more than this value. Unsupported for yahoo source.", + "description": "News stories will have a business relevance score more than this value. Unsupported for yahoo source. Value is a decimal between 0 and 1.", "default": null, "optional": true, "choices": null @@ -31083,7 +31083,7 @@ { "name": "business_relevance_less_than", "type": "float", - "description": "News stories will have a business relevance score less than this value. Unsupported for yahoo source.", + "description": "News stories will have a business relevance score less than this value. Unsupported for yahoo source. Value is a decimal between 0 and 1.", "default": null, "optional": true, "choices": null diff --git a/openbb_platform/openbb/package/news.py b/openbb_platform/openbb/package/news.py index b0e65cd2ab2..703eb34a046 100644 --- a/openbb_platform/openbb/package/news.py +++ b/openbb_platform/openbb/package/news.py @@ -112,9 +112,9 @@ class ROUTER_news(Container): is_spam : Optional[bool] Filter whether it is marked as spam or not. Unsupported for yahoo source. (provider: intrinio) business_relevance_greater_than : Optional[float] - News stories will have a business relevance score more than this value. Unsupported for yahoo source. (provider: intrinio) + News stories will have a business relevance score more than this value. Unsupported for yahoo source. Value is a decimal between 0 and 1. (provider: intrinio) business_relevance_less_than : Optional[float] - News stories will have a business relevance score less than this value. Unsupported for yahoo source. (provider: intrinio) + News stories will have a business relevance score less than this value. Unsupported for yahoo source. Value is a decimal between 0 and 1. (provider: intrinio) offset : Optional[int] Page offset, used in conjunction with limit. (provider: tiingo) @@ -327,9 +327,9 @@ class ROUTER_news(Container): is_spam : Optional[bool] Filter whether it is marked as spam or not. Unsupported for yahoo source. (provider: intrinio) business_relevance_greater_than : Optional[float] - News stories will have a business relevance score more than this value. Unsupported for yahoo source. (provider: intrinio) + News stories will have a business relevance score more than this value. Unsupported for yahoo source. Value is a decimal between 0 and 1. (provider: intrinio) business_relevance_less_than : Optional[float] - News stories will have a business relevance score less than this value. Unsupported for yahoo source. (provider: intrinio) + News stories will have a business relevance score less than this value. Unsupported for yahoo source. Value is a decimal between 0 and 1. (provider: intrinio) offset : Optional[int] Page offset, used in conjunction with limit. (provider: tiingo) diff --git a/openbb_platform/providers/intrinio/openbb_intrinio/models/company_news.py b/openbb_platform/providers/intrinio/openbb_intrinio/models/company_news.py index d70a7734f75..7577e4225e9 100644 --- a/openbb_platform/providers/intrinio/openbb_intrinio/models/company_news.py +++ b/openbb_platform/providers/intrinio/openbb_intrinio/models/company_news.py @@ -1,8 +1,9 @@ """Intrinio Company News Model.""" import asyncio -from datetime import datetime +from datetime import datetime, timedelta from typing import Any, Dict, List, Literal, Optional, Union +from warnings import warn from openbb_core.provider.abstract.fetcher import Fetcher from openbb_core.provider.standard_models.company_news import ( @@ -66,13 +67,17 @@ class IntrinioCompanyNewsQueryParams(CompanyNewsQueryParams): ) business_relevance_greater_than: Optional[float] = Field( default=None, + ge=0, + le=1, description="News stories will have a business relevance score more than this value." - + " Unsupported for yahoo source.", + + " Unsupported for yahoo source. Value is a decimal between 0 and 1.", ) business_relevance_less_than: Optional[float] = Field( default=None, + ge=0, + le=1, description="News stories will have a business relevance score less than this value." - + " Unsupported for yahoo source.", + + " Unsupported for yahoo source. Value is a decimal between 0 and 1.", ) @@ -164,7 +169,18 @@ class IntrinioCompanyNewsFetcher( @staticmethod def transform_query(params: Dict[str, Any]) -> IntrinioCompanyNewsQueryParams: """Transform the query params.""" - return IntrinioCompanyNewsQueryParams(**params) + transformed_params = params + if not transformed_params.get("start_date"): + transformed_params["start_date"] = ( + datetime.now() - timedelta(days=365) + ).date() + if not transformed_params.get("end_date"): + transformed_params["end_date"] = (datetime.now() + timedelta(days=1)).date() + if transformed_params["start_date"] == transformed_params["end_date"]: + transformed_params["end_date"] = ( + transformed_params["end_date"] + timedelta(days=1) + ).date() + return IntrinioCompanyNewsQueryParams(**transformed_params) @staticmethod async def aextract_data( @@ -199,23 +215,26 @@ class IntrinioCompanyNewsFetcher( # query.limit can be None... limit = query.limit or 2500 while next_page and limit > articles: - url = f"{base_url}/{symbol}/news?{query_str}&api_key={api_key}&next_page={next_page}" + url = ( + f"{base_url}/{symbol}/news?{query_str}" + + f"&page_size={query.limit}&api_key={api_key}&next_page={next_page}" + ) result = await get_data(url, session=session, **kwargs) _data = result.get("news", []) if _data: data.extend([{"symbol": symbol, **d} for d in _data]) articles = len(data) next_page = result.get("next_page") - # Remove duplicates based on URL return data seen = set() async def get_one(symbol): """Get the data for one symbol.""" - # TODO: Change page_size to a more appropriate value when Intrinio fixes the bug in this param. - url = f"{base_url}/{symbol}/news?{query_str}&page_size=99&api_key={api_key}" + url = f"{base_url}/{symbol}/news?{query_str}&page_size={query.limit}&api_key={api_key}" data = await amake_request(url, response_callback=callback, **kwargs) + if not data: + warn(f"No data found for: {symbol}") if data: data = [x for x in data if not (x["url"] in seen or seen.add(x["url"]))] # type: ignore news.extend( @@ -229,7 +248,10 @@ class IntrinioCompanyNewsFetcher( await asyncio.gather(*tasks) if not news: - raise EmptyDataError("Error: The request was returned as empty.") + raise EmptyDataError( + "Error: The request was returned as empty." + + " Try adjusting the requested date ranges, if applicable." + ) return news diff --git a/openbb_platform/providers/intrinio/openbb_intrinio/models/world_news.py b/openbb_platform/providers/intrinio/openbb_intrinio/models/world_news.py index 9be9ca3b5d5..b625d91267c 100644 --- a/openbb_platform/providers/intrinio/openbb_intrinio/models/world_news.py +++ b/openbb_platform/providers/intrinio/openbb_intrinio/models/world_news.py @@ -1,6 +1,8 @@ """Intrinio World News Model.""" -from datetime import datetime +# pylint: disable=unused-argument + +from datetime import datetime, timedelta from typing import Any, Dict, List, Literal, Optional, Union from openbb_core.provider.abstract.fetcher import Fetcher @@ -60,13 +62,17 @@ class IntrinioWorldNewsQueryParams(WorldNewsQueryParams): ) business_relevance_greater_than: Optional[float] = Field( default=None, + ge=0, + le=1, description="News stories will have a business relevance score more than this value." - + " Unsupported for yahoo source.", + + " Unsupported for yahoo source. Value is a decimal between 0 and 1.", ) business_relevance_less_than: Optional[float] = Field( default=None, + ge=0, + le=1, description="News stories will have a business relevance score less than this value." - + " Unsupported for yahoo source.", + + " Unsupported for yahoo source. Value is a decimal between 0 and 1.", ) @@ -161,7 +167,16 @@ class IntrinioWorldNewsFetcher( @staticmethod def transform_query(params: Dict[str, Any]) -> IntrinioWorldNewsQueryParams: """Transform the query params.""" - return IntrinioWorldNewsQueryParams(**params) + transformed_params = params + if not transformed_params.get("start_date"): + transformed_params["start_date"] = datetime.now().date() + if not transformed_params.get("end_date"): + transformed_params["end_date"] = (datetime.now() + timedelta(days=1)).date() + if transformed_params["start_date"] == transformed_params["end_date"]: + transformed_params["end_date"] = ( + transformed_params["end_date"] + timedelta(days=1) + ).date() + return IntrinioWorldNewsQueryParams(**transformed_params) @staticmethod async def aextract_data( @@ -179,9 +194,7 @@ class IntrinioWorldNewsFetcher( else ["symbol", "page_size"] ) query_str = get_querystring(query.model_dump(by_alias=True), ignore) - # TODO: Change page_size to a more appropriate value when Intrinio fixes the bug in this param. - url = f"{base_url}/news?{query_str}&page_size=99&api_key={api_key}" - + url = f"{base_url}/news?{query_str}&page_size={query.limit}&api_key={api_key}" seen = set() async def callback(response, session): @@ -195,7 +208,7 @@ class IntrinioWorldNewsFetcher( articles = len(data) next_page = result.get("next_page") while next_page and articles < query.limit: - url = f"{base_url}/news?{query_str}&page_size=99&api_key={api_key}&next_page={next_page}" + url = f"{base_url}/news?{query_str}&page_size={query.limit}&api_key={api_key}&next_page={next_page}" result = await get_data(url, session=session, **kwargs) _data = result.get("news", []) if _data: @@ -213,16 +226,18 @@ class IntrinioWorldNewsFetcher( : query.limit ] - return await amake_request(url, response_callback=callback, **kwargs) + return await amake_request(url, response_callback=callback, **kwargs) # type: ignore - # pylint: disable=unused-argument @staticmethod def transform_data( query: IntrinioWorldNewsQueryParams, data: List[Dict], **kwargs: Any ) -> List[IntrinioWorldNewsData]: """Return the transformed data.""" if not data: - raise EmptyDataError("Error: The request was returned as empty.") + raise EmptyDataError( + "Error: The request was returned as empty." + + " Try adjusting the requested date ranges, if applicable." + ) results: List[IntrinioWorldNewsData] = [] for item in data: body = item.get("body", {}) |