-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlayoffFantasyFootballSquads.py
49 lines (47 loc) · 2.06 KB
/
PlayoffFantasyFootballSquads.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import requests
import csv
import time
time.sleep(1)
# need to register with different mail to https://developer.sportradar.com/ every year and get a new trial api_key
api_key = "Hvuejf6RpLrRzhu5KgkLDy7ymwfck5g2kJ3wxlDY"
response = requests.get('https://api.sportradar.us/nfl/official/trial/v7/en/seasons/2024/REG/standings/season.json?api_key={}'.format(api_key))
standings = response.json()
conferences = standings["conferences"]
position_mapping = {
"CB": "DP",
"DB": "DP",
"DE": "DP",
"DT": "DP",
"FB": "RB",
"K": "K",
"LB": "DP",
"QB": "QB",
"RB": "RB",
"SAF": "DP",
"TE": "TE",
"WR": "WR"
}
with open('/Users/hagrubma/NFLRosters.csv', 'w') as rosters_file:
rosters_file_writer = csv.writer(rosters_file)
for conference in conferences:
print("processing {} conference".format(conference["name"]))
divisions = conference["divisions"]
for division in divisions:
print("processing {} division".format(division["name"]))
teams = division["teams"]
for team in teams:
team_name = "{} {}".format(team["market"], team["name"])
print("processing {}".format(team_name))
team_id = team["id"]
roster_url = "https://api.sportradar.us/nfl/official/trial/v7/en/teams/{}/full_roster.json?api_key={}".format(team_id, api_key)
print("calling roster url - {}".format(roster_url))
time.sleep(1)
roster_response = requests.get("https://api.sportradar.us/nfl/official/trial/v7/en/teams/{}/full_roster.json?api_key={}".format(team_id, api_key))
roster = roster_response.json()
players = roster["players"]
rosters_file_writer.writerow([team_name, "D/ST", team_name])
for player in players:
position = player["position"]
if position in position_mapping:
name = player["name"]
rosters_file_writer.writerow([team_name, position_mapping[position], name])