Chosen API Link: https://sports.core.api.espn.com/v2/sports/football/leagues/nfl/seasons/2022/types/2/weeks/16/events
From this API, I am attempting to extract 12 pieces of data for each team (32 teams), so that I can plug those numbers into a formula and predict the winners of matchups. I created a dictionary to format how I want to store the data here: https://pastebin.com/cK1wJ0ZS (Teams are represented by their "id" in the index) Their ID is assigned in the API.
When I run my data extract file ( https://pastebin.com/LwGus277 ), 60 entries are entered into the categories I have written. This is coming from the loop in my fill_game()
method. I do not understand why all 60 are coming through.
for game in range(len(games["items"])):
self.fill_home_team(games["items"][game]["$ref"])
Each list's length inside of my sub-categories should be equal to the last_games param of __init__
, but it is 60 now.
If last_games was 1, then there would only be 1 week's worth of games, and since each team plays once per week, there should be 1 piece of data per category.
If anyone could help that would be greatly appreciated!
I've gone through and followed the instructions line by line as if I was the computer, and still could not understand how these numbers were being looped in.
EDIT: I have tried debugging these lines in PyCharm:
# Add Turnover Differential
self.stats[team_id - 1][0]["Turnover Differential"].append(path[10]["stats"][39]["value"])
# Add RedZone Efficiency
self.stats[team_id - 1][1]["RedZone Efficiency"].append(path[10]["stats"][12]["value"])
# Add Third Down Attempts
self.stats[team_id - 1][2]["Third Down Attempts"].append(path[10]["stats"][29]["value"])
I noticed that instead of putting the team's data in their respective index at [team_id - 1], it is appending the data to EVERY team's list. I cannot figure out why that is happening. Maybe I'm overlooking something?