Пример #1
0
    def __init__(self, year, week):
        """
        Object that represents the weekly box scores page
        NOTE: only implemented for regular season right now
        :param year: year to get data for
        :param week: week to get data from
        """
        if not 1 <= week <= 17:
            raise ValueError("Week must be between 1 and 17 (inclusive).")

        if not 2003 <= year <= 2015:
            raise ValueError("Year must be between 2003 and 2015 (inclusive)...at least at the time of writing :)")

        url = self._url_format.format(year=year, week=week)
        self._response = get_page(url)
Пример #2
0
    def __init__(self, game_id):
        """
        Get the box score page
        :param game_id: game_id
        """
        self._game_id = game_id
        url = self._url_format.format(game_id=game_id)
        self._soup = BeautifulSoup(get_page(url))

        self._home = self._soup.find("div", "team home").find("span", "abbrev").text
        self._away = self._soup.find("div", "team away").find("span", "abbrev").text

        try:
            self._home_score = int(self._soup.find("div", "team home").find("div", "score-container").text)
            self._away_score = int(self._soup.find("div", "team away").find("div", "score-container").text)
        except ValueError:
            # The game hasn't happened yet
            self._home_score = None
            self._away_score = None