-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.py
70 lines (64 loc) · 1.08 KB
/
api.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Modified at: 2024.2.5
# Author: Steven
# Usage: grab data from SportsDataIO api
import requests
import json
from config import headers
month_strf = {
"01": "JAN",
"02": "FEB",
"03": "MAR",
"04": "APR",
"05": "MAY",
"06": "JUN",
"07": "JUL",
"08": "AUG",
"09": "SEP",
"10": "OCT",
"11": "NOV",
"12": "DEC",
}
team_list = [
"TB",
"BAL",
"NYY",
"TOR",
"BOS",
"MIN",
"CLE",
"DET",
"CHW",
"KC",
"TEX",
"HOU",
"SEA",
"LAA",
"OAK",
"ATL",
"PHI",
"MIA",
"NYM",
"WSH",
"MIL",
"CIN",
"PIT",
"CHC",
"STL",
"LAD",
"SF",
"SD",
"ARI",
"COL",
]
def main():
for team in team_list:
response = requests.get(
"https://api.sportsdata.io/v3/mlb/scores/json/Players/{}".format(team),
headers=headers,
)
data = response.json()
json_object = json.dumps(data)
with open("{}.json".format(team), "w") as outfile:
outfile.write(json_object)
if __name__ == "__main__":
main()