feat: key executives

This commit is contained in:
montezdesousa
2024-02-12 11:38:51 +00:00
parent 3cd7a4d169
commit aad97cd9ea
5 changed files with 12 additions and 23 deletions

View File

@@ -1,6 +1,6 @@
"""Key Executives Standard Model."""
from typing import List, Optional, Set, Union
from typing import Optional
from pydantic import Field, field_validator
@@ -16,11 +16,9 @@ class KeyExecutivesQueryParams(QueryParams):
@field_validator("symbol", mode="before", check_fields=False)
@classmethod
def upper_symbol(cls, v: Union[str, List[str], Set[str]]):
def upper_symbol(cls, v: str) -> str:
"""Convert symbol to uppercase."""
if isinstance(v, str):
return v.upper()
return ",".join([symbol.upper() for symbol in list(v)])
return v.upper()
class KeyExecutivesData(Data):

View File

@@ -5,8 +5,7 @@ from typing import Optional
def check_single(field: str, value: Optional[str]) -> Optional[str]:
"""Check that string is a single value."""
if value:
if "," in value or ";" in value:
if value and ("," in value or ";" in value):
raise ValueError(f"multiple values not allowed for field '{field}'")
return value

View File

@@ -18,6 +18,8 @@ class FMPKeyExecutivesQueryParams(KeyExecutivesQueryParams):
Source: https://financialmodelingprep.com/developer/docs/#Key-Executives
"""
__validator_dict__ = {"check_single": ("symbol",)}
class FMPKeyExecutivesData(KeyExecutivesData):
"""FMP Key Executives Data."""

View File

@@ -1,7 +1,6 @@
"""YFinance Historical Dividends Model."""
# pylint: disable=unused-argument
import warnings
from typing import Any, Dict, List, Optional
from openbb_core.provider.abstract.fetcher import Fetcher
@@ -11,8 +10,6 @@ from openbb_core.provider.standard_models.historical_dividends import (
)
from yfinance import Ticker
_warn = warnings.warn
class YFinanceHistoricalDividendsQueryParams(HistoricalDividendsQueryParams):
"""YFinance Historical Dividends Query."""

View File

@@ -1,7 +1,6 @@
"""YFinance Key Executives Model."""
# pylint: disable=unused-argument
import warnings
from typing import Any, Dict, List, Optional
from openbb_core.provider.abstract.fetcher import Fetcher
@@ -12,12 +11,12 @@ from openbb_core.provider.standard_models.key_executives import (
from pydantic import Field
from yfinance import Ticker
_warn = warnings.warn
class YFinanceKeyExecutivesQueryParams(KeyExecutivesQueryParams):
"""YFinance Key Executives Query."""
__validator_dict__ = {"check_single": ("symbol",)}
class YFinanceKeyExecutivesData(KeyExecutivesData):
"""YFinance Key Executives Data."""
@@ -29,6 +28,7 @@ class YFinanceKeyExecutivesData(KeyExecutivesData):
"exercised_value": "exercisedValue",
"unexercised_value": "unexercisedValue",
}
__validator_dict__ = {"check_single": ("symbol",)}
exercised_value: Optional[int] = Field(
default=None,
@@ -57,19 +57,12 @@ class YFinanceKeyExecutivesFetcher(
**kwargs: Any,
) -> List[Dict]:
"""Extract the raw data from YFinance."""
symbols = query.symbol.split(",")
symbol = symbols[0]
if len(symbols) > 1:
_warn(
"Lists of symbols are not allowed for this function. "
f"Multiple symbols will be ignored in favour of the first symbol. {symbol}"
)
try:
ticker = Ticker(symbol).get_info()
ticker = Ticker(query.symbol).get_info()
except Exception as e:
raise RuntimeError(f"Error getting data for {symbol}: {e}") from e
raise RuntimeError(f"Error getting data for {query.symbol}: {e}") from e
if ticker.get("companyOfficers") is None:
raise ValueError(f"No executive data found for {symbol}")
raise ValueError(f"No executive data found for {query.symbol}")
officers_data = ticker.get("companyOfficers", [])
[d.pop("maxAge") for d in officers_data] # pylint: disable=W0106
return officers_data