Repository: OpenBB-finance/OpenBBTerminal
File: openbb_platform/providers/polygon/openbb_polygon/models/company_news.py (Python)

Code before:
"""Polygon Company News Model."""


from typing import Any, Dict, List, Literal, Optional

from openbb_core.provider.abstract.fetcher import Fetcher
from openbb_core.provider.standard_models.company_news import (
    CompanyNewsData,
    CompanyNewsQueryParams,
)
from openbb_core.provider.utils.helpers import get_querystring
from openbb_polygon.utils.helpers import get_data_many, get_date_condition
from pydantic import BaseModel, Field, field_validator


class PolygonCompanyNewsQueryParams(CompanyNewsQueryParams):
    """Polygon Company News Query.

    Source: https://polygon.io/docs/stocks/get_v2_reference_news
    """

    __alias_dict__ = {"symbols": "tickers"}

    published_utc: Optional[str] = Field(
        default=None,
        description="Date query to fetch articles. Supports operators <, <=, >, >=",
    )
    order: Optional[Literal["asc", "desc"]] = Field(
        default="desc", description="Sort order of the articles."
    )

    @field_validator("limit", mode="before")
    def limit_validator(cls, v: int) -> int:  # pylint: disable=E0213
        """Limit validator."""
        return min(v, 1000)


class PolygonPublisher(BaseModel):
    """PolygonPublisher Data Model."""

    favicon_url: str = Field(description="Favicon URL.")
    homepage_url: str = Field(description="Homepage URL.")
    logo_url: str = Field(description="Logo URL.")
    name: str = Field(description="Publisher Name.")


class PolygonCompanyNewsData(CompanyNewsData):

Review comment (suggestion):
Polygon calls the parameter `ticker`, and it also doesn't support multiple symbols to the News endpoint.

Code after:
"""Polygon Company News Model."""


from typing import Any, Dict, List, Literal, Optional

from openbb_core.provider.abstract.fetcher import Fetcher
from openbb_core.provider.standard_models.company_news import (
    CompanyNewsData,
    CompanyNewsQueryParams,
)
from openbb_core.provider.utils.helpers import get_querystring
from openbb_polygon.utils.helpers import get_data_many, get_date_condition
from pydantic import BaseModel, Field, field_validator


class PolygonCompanyNewsQueryParams(CompanyNewsQueryParams):
    """Polygon Company News Query.

    Source: https://polygon.io/docs/stocks/get_v2_reference_news
    """

    __alias_dict__ = {"symbols": "ticker"}

    published_utc: Optional[str] = Field(
        default=None,
        description="Date query to fetch articles. Supports operators <, <=, >, >=",
    )
    order: Optional[Literal["asc", "desc"]] = Field(
        default="desc", description="Sort order of the articles."
    )

    @field_validator("limit", mode="before")
    def limit_validator(cls, v: int) -> int:  # pylint: disable=E0213
        """Limit validator."""
        return min(v, 1000)


class PolygonPublisher(BaseModel):
    """PolygonPublisher Data Model."""

    favicon_url: str = Field(description="Favicon URL.")
    homepage_url: str = Field(description="Homepage URL.")
    logo_url: str = Field(description="Logo URL.")
    name: str = Field(description="Publisher Name.")


class PolygonCompanyNewsData(CompanyNewsData):