-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetters.py
103 lines (82 loc) · 2.94 KB
/
getters.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import json
year = 2024
write_file_path = "data/stat/league/{}.json"
player_stats_path = "data/stat/players/stats/{}.json"
standings_path = "data/team/standings/{}.json"
team_path = "data/team/teams/{}.json"
player_grades_path = "data/stat/players/grades/{}.json"
team_grades_path = "data/team/grades/{}.json"
def get_player_stats(date_string, categories):
f = open(player_stats_path.format(date_string), 'r')
data = json.load(f)
f.close()
stats = {}
for player in data:
stats[player]= {}
for category in categories:
stats[player][category] = data[player][category]
stats[player]["G"] = data[player]["G"]
stats[player]["id"] = data[player]["id"]
stats[player]["img"] = data[player]["img"]
stats[player]["name"] = data[player]["Player"]
stats[player]["last_update"] = data[player]["last_update"]
stats[player]["age"] = data[player]["Age"]
stats[player]["pos"] = data[player]["Pos"]
stats[player]["link"] = data[player]["link"]
if isinstance(data[player]["Team"], list):
team = data[player]["Team"][-1]
else:
team = data[player]["Team"]
stats[player]["team"] = team
return stats
def get_team_stats(date_string, categories):
f = open(write_file_path.format(date_string), 'r')
data = json.load(f)
f.close()
stats = {}
for team in data:
stat_ranks = {}
for cat in data[team]["stats"]["Lg Rank"]:
if cat in categories:
stat_ranks[cat] = data[team]["stats"]["Lg Rank"][cat]
for cat in data[team]["stats"]["Opp Lg Rank"]:
if cat in categories:
stat_ranks[f'O_{cat}'] = data[team]["stats"]["Opp Lg Rank"][cat]
j = {
"Tm": team,
"RRK": data[team]["standings"]["Rk"],
"Name": data[team]["standings"]["Team"],
"img": data[team]["img"],
"Players": data[team]["roster"],
"stat_ranks": stat_ranks,
'standing': data[team]["info"]["standing"],
"last_update": data[team]["last_update"]
}
stats[team] = j
return stats
def get_grades(date_string):
f = open(player_grades_path.format(date_string), 'r')
data = json.load(f)
f.close()
return data
def get_team_stats_quick(date_string):
f = open(write_file_path.format(date_string), 'r')
data = json.load(f)
f.close()
stats = {}
for team in data:
j = {
"Tm": team,
"RRK": data[team]["standings"]["Rk"],
"Name": data[team]["standings"]["Team"],
"img": data[team]["img"],
'standing': data[team]["info"]["standing"],
"last_update": data[team]["last_update"]
}
stats[team] = j
return stats
def get_grades_team(date_string):
f = open(team_grades_path.format(date_string), 'r')
data = json.load(f)
f.close()
return data