-
Notifications
You must be signed in to change notification settings - Fork 0
/
history.py
80 lines (46 loc) · 1.93 KB
/
history.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
import json
class History(object):
def __init__(self):
with open('allgames.json') as data_file:
self.games = json.load(data_file)
with open('teams.json') as data_file:
self.servers = json.load(data_file)
self.history = []
self.create_history()
def create_history(self):
for game in self.games:
winner = self.get_team(game['winner']['name'])
loser = self.get_team(game['loser']['name'])
if winner and loser:
game['winner']['players'] = winner.get('players')[:+4]
game['loser']['players'] = loser.get('players')[:+4]
del game['winner']['url']
del game['loser']['url']
game['winner']['composition'] = winner['composition']
game['loser']['composition'] = loser['composition']
self.history.append(game)
with open('history.json', 'w') as outfile:
json.dump(self.history, outfile)
def get_team(self, team_name):
server = self.get_server(team_name[:-2].replace('-', ' '))
try:
for team in server['teams']:
if team['name'] == team_name:
return team
except TypeError:
pass
def get_server(self, server_name):
for server in self.servers:
if server['name'] == server_name:
return server
# for death in game['winner']['deaths']:
# if winner['players']['death']:
# winner['players']['death'] += 1
# else:
# winner['players']['death'] = 1
# for death in game['loser']['deaths']:
# if loser['players']['death']:
# loser['players']['death'] += 1
# else:
# loser['players']['death'] = 1
history = History()