def parse_players(self, team, table):
     metrics = [metric.text for metric in
                table.find('thead').find_all('tr')[1].find_all('th')[1:]]
     rows = table.find('tbody').find_all('tr')
     rows.pop(5)
     for player in rows:
         name = player.th.a.text
         stats = [inf.text for inf in player.find_all('td')]
         for metric, stat in zip(metrics, stats):
             stat = stat if stat != '' else None
             if metric == 'MP':
                 stat = stat if stat not in [None, 'Did Not Play', 'Player Suspended'] else '0.0'
                 stat = convert_to_min(stat)
             stat = float(stat) if stat else None
             self.match_[team]['players'][name][metric] = stat
Exemple #2
0
    def _read_table(self, table, last_col):
        """
        reads given table and updates relevant stats in match dict
        """
        away, home = table[0], table[1]
        for team, table in zip(['away', 'home'], [away, home]):
            metrics = table.find('thead').find_all('tr')[1].find_all('th')[1:]
            metrics = [metric.text for metric in metrics]

            # generate team totals stats
            team_totals = table.find('tfoot').find_all('td')[1:]
            if not last_col:
                team_totals.pop(-1)
                m = metrics[:-1]
            else:
                m = metrics
            t = [float(total.text) for total in team_totals]
            self.match_[team]['totals'].update(dict(zip(m, t)))

            # generate players stats
            rows = table.find('tbody').find_all('tr')
            rows.pop(5)
            for player in rows:
                player_stats = [inf.text for inf in player.find_all('td')]
                player_name = player_stats.pop(0)

                for metric, stat in zip(metrics, player_stats):
                    if stat == '':
                        stat = None
                    if metric == 'MP':
                        if stat is None or stat == 'Did Not Play' or stat == 'Player Suspended':
                            stat = 0.0
                        else:
                            stat = convert_to_min(stat)
                    stat = float(stat) if stat else None
                    self.match_[team]['players'][player_name][metric] = stat
Exemple #3
0
    def _read_table(self, table, last_col):
        """
        reads given table and updates relevant stats in match dict
        """
        away, home = table[0], table[1]
        for team, table in zip(['away', 'home'], [away, home]):
            metrics = table.find('thead').find_all('tr')[1].find_all('th')[1:]
            metrics = [metric.text for metric in metrics]

            # generate team totals stats
            team_totals = table.find('tfoot').find_all('td')[1:]
            if not last_col:
                team_totals.pop(-1)
                m = metrics[:-1]
            else:
                m = metrics
            t = [float(total.text) for total in team_totals]
            self.match_[team]['totals'].update(dict(zip(m, t)))

            # generate players stats
            rows = table.find('tbody').find_all('tr')
            rows.pop(5)
            for player in rows:
                player_stats = [inf.text for inf in player.find_all('td')]
                player_name = player_stats.pop(0)

                for metric, stat in zip(metrics, player_stats):
                    if stat == '':
                        stat = None
                    if metric == 'MP':
                        if stat is None or stat == 'Did Not Play' or stat == 'Player Suspended':
                            stat = 0.0
                        else:
                            stat = convert_to_min(stat)
                    stat = float(stat) if stat else None
                    self.match_[team]['players'][player_name][metric] = stat