Feature/general fixes (#5786)

* fix mypy

* import helper from source

* improve missing api key msg

* fix

* remove dynamic default

* rename rest_api_settings file

* add comment async/sync

* fix bug

* Revert "fix bug"

This reverts commit 7d9a0d2749.

* fix bug
This commit is contained in:
montezdesousa
2023-11-23 16:16:56 +00:00
committed by GitHub
parent bc2fa9b3e1
commit bb5e76ce5c
11 changed files with 31 additions and 53 deletions

View File

@@ -117,7 +117,7 @@ class ParametersBuilder:
command_coverage: Dict[str, List[str]],
route: str,
kwargs: Dict[str, Any],
route_default: Optional[str],
route_default: Optional[Dict[str, Optional[str]]],
) -> Dict[str, Any]:
"""Update the provider choices with the available providers and set default provider."""
@@ -143,7 +143,7 @@ class ParametersBuilder:
def _get_default_provider(
command_coverage: Dict[str, List[str]],
route_default: Optional[str],
route_default: Optional[Dict[str, Optional[str]]],
) -> Optional[str]:
"""Get the default provider for the given route.
Either pick it from the user defaults or from the command coverage."""

View File

@@ -13,7 +13,7 @@ from openbb_core.app.constants import (
USER_SETTINGS_PATH,
)
from openbb_core.app.model.abstract.tagged import Tagged
from openbb_core.app.model.rest_api_settings import FastAPISettings
from openbb_core.app.model.fast_api_settings import FastAPISettings
from openbb_core.app.version import VERSION

View File

@@ -51,7 +51,9 @@ class QueryExecutor:
credential_value = credentials.get(c)
if c not in credentials or credential_value is None:
if require_credentials:
raise ProviderError(f"Missing credential '{c}'.")
website = provider.website or ""
extra_msg = f"Check {website} to get it." if website else ""
raise ProviderError(f"Missing credential '{c}'. {extra_msg}")
else:
filtered_credentials[c] = credential_value.get_secret_value()

View File

@@ -7,7 +7,7 @@ from datetime import (
)
from typing import Literal, Optional
from pydantic import Field
from pydantic import Field, model_validator
from openbb_core.provider.abstract.data import Data
from openbb_core.provider.abstract.query_params import QueryParams
@@ -37,15 +37,27 @@ class USTreasuryAuctionsQueryParams(QueryParams):
alias="pagenum",
)
start_date: Optional[dateType] = Field(
default=(datetime.now() - timedelta(days=90)).strftime("%Y-%m-%d"),
default=None,
description=QUERY_DESCRIPTIONS.get("start_date", "")
+ " The default is 90 days ago.",
)
end_date: Optional[dateType] = Field(
default=datetime.now().strftime("%Y-%m-%d"),
default=None,
description=QUERY_DESCRIPTIONS.get("end_date", "") + " The default is today.",
)
@model_validator(mode="before")
@classmethod
def validate_dates(cls, values) -> dict:
"""Validate the query parameters."""
if values.get("start_date") is None:
values["start_date"] = (datetime.now() - timedelta(days=90)).strftime(
"%Y-%m-%d"
)
if values.get("end_date") is None:
values["end_date"] = datetime.now().strftime("%Y-%m-%d")
return values
class USTreasuryAuctionsData(Data):
"""US Treasury Auctions Data."""

View File

@@ -200,25 +200,6 @@ def to_snake_case(string: str) -> str:
)
def to_camel_case(string: str):
"""Convert a string to camel case.
If all characters are lower case we return title version of the string.
Examples
--------
"close" -> "Close"
"some_field" -> "someField"
"""
s_list = string.replace("-", " ").replace("_", " ").split()
if len(string) == 0:
return string
result = s_list[0] + "".join(i.capitalize() for i in s_list[1:])
if result.islower():
return result.title()
return result
async def maybe_coroutine(
func: Callable[P, Union[T, Awaitable[T]]], /, *args: P.args, **kwargs: P.kwargs
) -> T:

View File

@@ -6,7 +6,6 @@ from openbb_core.provider.utils.helpers import (
get_querystring,
get_user_agent,
make_request,
to_camel_case,
to_snake_case,
)
@@ -69,11 +68,3 @@ def test_to_snake_case():
assert to_snake_case("SomeRandomString") == "some_random_string"
assert to_snake_case("someRandomString") == "some_random_string"
assert to_snake_case("already_snake_case") == "already_snake_case"
def test_to_camel_case():
"""Test the to_camel_case helper."""
assert to_camel_case("some_field") == "someField"
assert to_camel_case("alreadyCamelCase") == "alreadyCamelCase"
assert to_camel_case("close") == "Close"
assert not to_camel_case("")

View File

@@ -79,7 +79,7 @@ class BiztocWorldNewsFetcher(
api_key = credentials.get("biztoc_api_key") if credentials else ""
data = get_news(
api_key=api_key, filter=query.filter, source=query.source, tag=query.tag, term=query.term # type: ignore
api_key=api_key, filter_=query.filter, source=query.source, tag=query.tag, term=query.term # type: ignore
)
if query.filter == "hot":
data = [post for sublist in data for post in sublist["posts"]]

View File

@@ -78,7 +78,7 @@ def get_all_tags(api_key) -> Dict[str, List[str]]:
def get_news(
api_key: str,
filter: Literal[
filter_: Literal[
"crypto", "hot", "latest", "main", "media", "source", "tag"
] = "latest",
source: str = "bloomberg",
@@ -115,16 +115,16 @@ def get_news(
"source": f"news/source/{source.lower()}",
"tag": f"tag/{tag}",
}
if filter == "source" and source.lower() not in sources:
if filter_ == "source" and source.lower() not in sources:
raise ValueError(f"{source} not a valid source. Valid sources: {sources}")
if filter == "tag" and tag.lower().replace(" ", "") not in tags:
if filter_ == "tag" and tag.lower().replace(" ", "") not in tags:
raise ValueError(f"{tag} not a valid tag. Valid tags: {tags}")
url = (
f"https://biztoc.p.rapidapi.com/search?q={term}"
if term
else f"https://biztoc.p.rapidapi.com/{filter_dict[filter]}"
else f"https://biztoc.p.rapidapi.com/{filter_dict[filter_]}"
)
r = requests.get(url, headers=headers, timeout=5)
if r.status_code != 200:

View File

@@ -79,8 +79,11 @@ class FMPEquityHistoricalFetcher(
return FMPEquityHistoricalQueryParams(**transformed_params)
# TODO: Fix fetcher to allow async/sync methods or turn everything async
# @overloading the method does not work, it breaks the type hinting for the
# synchronous method implemented in other providers
@staticmethod
async def extract_data(
async def extract_data( # pylint: disable=invalid-overridden-method
query: FMPEquityHistoricalQueryParams,
credentials: Optional[Dict[str, str]],
**kwargs: Any,

View File

@@ -1,9 +1,5 @@
"""US Government Treasury Auctions Model."""
from datetime import (
datetime,
timedelta,
)
from typing import Any, Dict, List, Optional
import pandas as pd
@@ -48,14 +44,7 @@ class GovernmentUSTreasuryAuctionsFetcher(
params: Dict[str, Any]
) -> GovernmentUSTreasuryAuctionsQueryParams:
"""Transform query params."""
transformed_params = params.copy()
if "start_date" not in transformed_params:
transformed_params["start_date"] = (
datetime.now() - timedelta(days=90)
).strftime("%Y-%m-%d")
if "end_date" not in transformed_params:
transformed_params["end_date"] = datetime.now().strftime("%Y-%m-%d")
return GovernmentUSTreasuryAuctionsQueryParams(**transformed_params)
return GovernmentUSTreasuryAuctionsQueryParams(**params)
@staticmethod
def extract_data(