Skip to content

Competition

Competition Class Documentation

Source code in pyespn/classes/event.py
@validate_json('competition_json')
class Competition:

    def __init__(self, competition_json, espn_instance, event_instance):
        self.competition_json = competition_json
        self._espn_instance = espn_instance
        self.event_instance = event_instance
        self._load_competition_data()

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

        Returns:
            str: A formatted string with the events/competition data.
        """
        return f"<Competition | {self.start_date}>"

    def _load_competition_data(self):
        self._id = self.competition_json.get("id")
        self.uid = self.competition_json.get("uid")
        self.date = self.competition_json.get("date")
        self.attendance = self.competition_json.get("attendance")
        self.type = self.competition_json.get("type")  # This might itself be a dict
        self.time_valid = self.competition_json.get("timeValid")
        self.geo_broadcast = self.competition_json.get("geoBroadcast")  # Might be a list of dicts
        self.play_by_play_available = self.competition_json.get("playByPlayAvailable")
        self.play_by_play_source = self.competition_json.get("playByPlaySource")
        self.boxscore_available = self.competition_json.get("boxscoreAvailable")
        self.roster_available = self.competition_json.get("rosterAvailable")
        self.broadcasts = self.competition_json.get("broadcasts")  # Likely a list of dicts
        self.status = self.competition_json.get("status")  # A dict with displayClock, period, etc.
        self.venue = self.event_instance.event_venue
        self.competitors = self.competition_json.get("competitors")  # A list of team info
        self.notes = self.competition_json.get("notes")  # Might be optional
        self.start_date = self.competition_json.get("startDate")
        self.neutral_site = self.competition_json.get("neutralSite")
        self.conference_competition = self.competition_json.get("conferenceCompetition")
        self.recent = self.competition_json.get("recent")
        self.location = self.competition_json.get("location")
        self.weather = self.competition_json.get("weather")  # Optional dict
        self.format = self.competition_json.get("format")
        self.leaders = self.competition_json.get("leaders")  # Usually a list of stats leaders
        self.headlines = self.competition_json.get("headlines")
        self.odds = self.competition_json.get("odds")  # List of betting odds
        self.notes = self.competition_json.get("notes")
        self.tickets = self.competition_json.get("tickets")
        self.group = self.competition_json.get("group")
        self.start_time_tbd = self.competition_json.get("startTimeTBD")
        self.targeting_data = self.competition_json.get("targetingData")
        self.qualifiers = self.competition_json.get("qualifiers")
        self.timeout_format = self.competition_json.get("timeoutFormat")
        self.game_package = self.competition_json.get("gamePackage")
        self.officials = self.competition_json.get('officials')
        self.predictions_available = self.competition_json.get("predictionsAvailable")
        self.clock = self.competition_json.get("clock")
        # nba has series
        self.series = self.competition_json.get('series')

    @property
    def id(self):
        """
            str: the id for the event
        """
        return self._id

    @property
    def espn_instance(self):
        """
            PYESPN: the espn client instance associated with the class
        """
        return self._espn_instance

    def to_dict(self) -> dict:
        """
        Converts the Competition instance to its original JSON dictionary.

        Returns:
            dict: The competitions's raw JSON data.
        """
        return self.competition_json

espn_instance property

PYESPN: the espn client instance associated with the class

id property

str: the id for the event

__repr__()

Returns a string representation of the Competition instance.

Returns:

Name Type Description
str str

A formatted string with the events/competition data.

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

    Returns:
        str: A formatted string with the events/competition data.
    """
    return f"<Competition | {self.start_date}>"

to_dict()

Converts the Competition instance to its original JSON dictionary.

Returns:

Name Type Description
dict dict

The competitions's raw JSON data.

Source code in pyespn/classes/event.py
def to_dict(self) -> dict:
    """
    Converts the Competition instance to its original JSON dictionary.

    Returns:
        dict: The competitions's raw JSON data.
    """
    return self.competition_json