Beispiel #1
0
def load_teams() -> Dict[str, Team]:
    """Return a dictionary of Teams keyed by competition slug. No players are loaded yet"""
    all_teams: Dict[str, Team] = {}
    HOME_TEAM_IDX = 3
    AWAY_TEAM_IDX = 4
    for f in os.listdir('data/teams/'):
        if f.endswith('.csv'):
            comp_teams = set()
            with open(os.path.join('data/teams', f)) as comp_file:
                reader = csv.reader(comp_file, delimiter=',')
                for i, row in enumerate(reader):
                    if i == 0:
                        continue  # skip header row
                    comp_teams.add(row[HOME_TEAM_IDX])
                    comp_teams.add(row[AWAY_TEAM_IDX])
            comp_slug = f.split('.')[0]
            all_teams[comp_slug] = [
                Team.new(comp_team) for comp_team in comp_teams
            ]
    return all_teams