Skip to content

Betting

Betting Class Documentation

Represents betting data within the ESPN API framework.

This class encapsulates details about betting providers and their odds.

Attributes:

Name Type Description
betting_json dict

The raw JSON data representing the betting details.

espn_instance PYESPN

The ESPN API instance for fetching additional data.

providers list

A list of Provider instances offering betting lines.

Methods:

Name Description
_set_betting_data

Parses and stores betting data, including providers.

__repr__

Returns a string representation of the Betting instance.

Source code in pyespn/classes/betting.py
@validate_json("betting_json")
class Betting:
    """
    Represents betting data within the ESPN API framework.

    This class encapsulates details about betting providers and their odds.

    Attributes:
        betting_json (dict): The raw JSON data representing the betting details.
        espn_instance (PYESPN): The ESPN API instance for fetching additional data.
        providers (list): A list of `Provider` instances offering betting lines.

    Methods:
        _set_betting_data():
            Parses and stores betting data, including providers.

        __repr__() -> str:
            Returns a string representation of the Betting instance.
    """

    def __init__(self, espn_instance, betting_json: dict):
        """
        Initializes a Betting instance.

        Args:
            espn_instance (PYESPN): The ESPN API instance for API interaction.
            betting_json (dict): The JSON data containing betting information.
        """
        self.betting_json = betting_json
        self.espn_instance = espn_instance
        self.providers = []
        self._set_betting_data()

    def __repr__(self) -> str:
        """
        Returns a string representation of the Betting instance.

        Returns:
            str: A formatted string with the bettings information .
        """
        return f"<Betting | {self.display_name} - {self.espn_instance.league_abbv}>"

    def _set_betting_data(self):
        """
        Private method to parse and store betting data, including providers.
        """
        self.id = self.betting_json.get('id')
        self.ref = self.betting_json.get('$ref')
        self.name = self.betting_json.get('name')
        self.display_name = self.betting_json.get('displayName')
        for provider in self.betting_json.get('futures'):
            self.providers.append(Provider(espn_instance=self.espn_instance,
                                           line_json=provider))

__init__(espn_instance, betting_json)

Initializes a Betting instance.

Parameters:

Name Type Description Default
espn_instance PYESPN

The ESPN API instance for API interaction.

required
betting_json dict

The JSON data containing betting information.

required
Source code in pyespn/classes/betting.py
def __init__(self, espn_instance, betting_json: dict):
    """
    Initializes a Betting instance.

    Args:
        espn_instance (PYESPN): The ESPN API instance for API interaction.
        betting_json (dict): The JSON data containing betting information.
    """
    self.betting_json = betting_json
    self.espn_instance = espn_instance
    self.providers = []
    self._set_betting_data()

__repr__()

Returns a string representation of the Betting instance.

Returns:

Name Type Description
str str

A formatted string with the bettings information .

Source code in pyespn/classes/betting.py
def __repr__(self) -> str:
    """
    Returns a string representation of the Betting instance.

    Returns:
        str: A formatted string with the bettings information .
    """
    return f"<Betting | {self.display_name} - {self.espn_instance.league_abbv}>"