mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-28 04:02:24 +00:00
refactor globalnews
This commit is contained in:
@@ -1,40 +1,26 @@
|
||||
"""FMP Global News fetcher."""
|
||||
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Dict, List, Optional
|
||||
|
||||
from openbb_provider.abstract.data import Data, QueryParams
|
||||
from openbb_provider.abstract.fetcher import Fetcher
|
||||
from openbb_provider.helpers import data_transformer
|
||||
from openbb_provider.models.global_news import GlobalNewsData, GlobalNewsQueryParams
|
||||
from pydantic import Field
|
||||
|
||||
from openbb_fmp.utils.helpers import create_url, get_data_many
|
||||
|
||||
|
||||
class FMPGlobalNewsQueryParams(QueryParams):
|
||||
class FMPGlobalNewsQueryParams(GlobalNewsQueryParams):
|
||||
"""FMP Global News query.
|
||||
|
||||
Source: https://site.financialmodelingprep.com/developer/docs/general-news-api/
|
||||
|
||||
Parameter
|
||||
---------
|
||||
page : int (default: 0)
|
||||
The page of the data to retrieve.
|
||||
"""
|
||||
|
||||
page: int = Field(default=0)
|
||||
|
||||
|
||||
class FMPGlobalNewsData(Data):
|
||||
publishedDate: datetime = Field(alias="date")
|
||||
title: str
|
||||
image: str
|
||||
text: str
|
||||
url: str
|
||||
site: str
|
||||
class FMPGlobalNewsData(GlobalNewsData):
|
||||
# publishedDate: datetime = Field(alias="date")
|
||||
class Config:
|
||||
fields = {'date': 'publishedDate'}
|
||||
|
||||
site: str = Field(description="The site of the news.")
|
||||
|
||||
class FMPGlobalNewsFetcher(
|
||||
Fetcher[
|
||||
@@ -62,4 +48,4 @@ class FMPGlobalNewsFetcher(
|
||||
|
||||
@staticmethod
|
||||
def transform_data(data: List[FMPGlobalNewsData]) -> List[GlobalNewsData]:
|
||||
return data_transformer(data, GlobalNewsData)
|
||||
return data
|
||||
|
||||
@@ -51,9 +51,9 @@ class Fetcher(
|
||||
credentials: Optional[Dict[str, str]] = None,
|
||||
) -> UDataType:
|
||||
"""Fetch data from a provider by using the OpenBB standard."""
|
||||
provider_query = cls.transform_query(query=query, extra_params=extra_params)
|
||||
provider_data = cls.extract_data(query=provider_query, credentials=credentials)
|
||||
data = cls.transform_data(data=provider_data)
|
||||
query = cls.transform_query(query=query, extra_params=extra_params)
|
||||
data = cls.extract_data(query=query, credentials=credentials)
|
||||
# data = cls.transform_data(data=data)
|
||||
return data
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -10,36 +10,16 @@ from openbb_provider.abstract.data import Data, QueryParams
|
||||
|
||||
|
||||
class GlobalNewsQueryParams(QueryParams):
|
||||
"""Global news query.
|
||||
"""Global news query."""
|
||||
|
||||
Parameter
|
||||
---------
|
||||
page : NonNegativeInt
|
||||
The page of the global news to be retrieved.
|
||||
"""
|
||||
|
||||
page: NonNegativeInt = Field(default=0)
|
||||
page: NonNegativeInt = Field(default=0, description="The page of the global news.")
|
||||
|
||||
|
||||
class GlobalNewsData(Data):
|
||||
"""Return Global News Data.
|
||||
"""Return Global News Data."""
|
||||
|
||||
Returns
|
||||
-------
|
||||
date : datetime
|
||||
The published date of the news.
|
||||
title : str
|
||||
The title of the news.
|
||||
image : Optional[str]
|
||||
The image URL of the news.
|
||||
text : str
|
||||
The text/body of the news.
|
||||
url : str
|
||||
The URL of the news.
|
||||
"""
|
||||
|
||||
date: datetime
|
||||
title: str
|
||||
image: Optional[str]
|
||||
text: str
|
||||
url: str
|
||||
date: datetime = Field(description="The published date of the news.")
|
||||
title: str = Field(description="The title of the news.")
|
||||
image: Optional[str] = Field(description="The image URL of the news.")
|
||||
text: str = Field(description="The text/body of the news.")
|
||||
url: str = Field(description="The URL of the news.")
|
||||
|
||||
Reference in New Issue
Block a user