Ejemplo n.º 1
0
    def scrape_score(self, team):
        '''
        Returns score of either the home or away team from the supplied
        BeautifulSoup4 rlproject match page as an integer.

        Args:
            team: string, either 'home' or 'away'

        Raises:
            DataError: unable to process the supplied data
        '''

        score_th = self.soup.find_all(
            'th',
            style='font-size:48pt;text-align:center;')

        if team == 'home':
            team_score = zero_bs4(score_th[0])
        elif team == 'away':
            team_score = zero_bs4(score_th[1])

        try:
            team_score = int(team_score)
        except ValueError:
            raise DataError(
                'Could not cast "{}" team score "{}" to int'.format(
                    team, team_score))

        return team_score
Ejemplo n.º 2
0
    def scrape_score(self, team):
        '''
        Returns score of either the home or away team from the supplied
        BeautifulSoup4 afltables match page as an integer.
        Args:
            team: string, either 'home' or 'away'
        Raises:
            DataError: unable to process the supplied data
        '''
        # get down to table rows
        rows = self.soup.findAll('tr')

        # get scores
        if team == 'home':
            team_score = zero_bs4(rows[19].findAll('td')[4])

        elif team == 'away':
            team_score = zero_bs4(rows[19].findAll('td')[9])

        # if we don't have something like an integer now, fail
        try:
            int(team_score)
        except ValueError:
            raise DataError(
                'Could not convert "{}" team score "{}" to int'.format(
                    team, team_score))

        return team_score
Ejemplo n.º 3
0
    def _player_row_as_dict(self, row):
        """Internal utility function. Takes a player row TR and returns it as
        a dict.
        Each player row contains the following information for the home and
        away player in a single position: position code (FB, WG, etc), name,
        number of tries, number of goals, number of field goals, and total
        points scored.
        """

        keys = ['home_pos_code', 'home_name', 'home_tries', 'home_goals',
                'home_fgoals', 'home_pts', 'away_pos_code', 'away_name',
                'away_tries', 'away_goals', 'away_fgoals', 'away_pts']

        cells = row.findAll('td')

        result = {k: v for k, v in zip(keys, [zero_bs4(td) for td in cells])}

        return result