-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatherGames.py
69 lines (51 loc) · 2.47 KB
/
gatherGames.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
import requests, json, os
urlTournament="http://api.lolesports.com/api/v1/scheduleItems?leagueId=9"
r = requests.get(urlTournament)
rawTournamentData = json.loads(r.text)
tournamentId = rawTournamentData['highlanderTournaments'][3]["id"]
#Get the bracket for Worlds 2018
brackets = rawTournamentData['highlanderTournaments'][3]["brackets"]
matches = []
games = {}
#Get the list of matches and each of their games
for bracketId in brackets:
bracket = brackets[bracketId]
for matchId in bracket["matches"]:
match = bracket["matches"][matchId]
for gameUuid in match['games']:
game = match['games'][gameUuid]
if 'gameId' in game:
games[gameUuid] = {"matchHistoryId":game['gameId'], "matchId":matchId, "realm":game["gameRealm"], "phase":bracket["groupName"]}
if os.path.isdir("./games"):
gamesSaved = [f.split(".")[0] for f in os.listdir("./games")]
else:
os.makedirs("./games")
gamesSaved=[]
matches = [games[gameUuid]["matchId"] for gameUuid in games if gameUuid not in gamesSaved]
baseMatchUrl = "http://api.lolesports.com/api/v2/highlanderMatchDetails?tournamentId="+tournamentId+"&matchId="
for matchId in matches:
r = requests.get(baseMatchUrl + matchId)
matchData = json.loads(r.text)
for i in matchData["gameIdMappings"]:
try:
games[i["id"]]["hash"] = i["gameHash"]
except:
print("Game "+str(i["id"]) + "has no hash")
baseMatchHistoryStatsUrl = "https://acs.leagueoflegends.com/v1/stats/game/{}/"
for gameUuid in games:
if gameUuid in gamesSaved:
continue
try:
r = requests.get(baseMatchHistoryStatsUrl.format(games[gameUuid]["realm"]) + games[gameUuid]["matchHistoryId"] + "?gameHash="+ games[gameUuid]["hash"])
if r.status_code == 200:
gameData = json.loads(r.text)
gameData["phase"] = games[gameUuid]["phase"]
r = requests.get(baseMatchHistoryStatsUrl.format(games[gameUuid]["realm"]) + games[gameUuid]["matchHistoryId"] + "/timeline?gameHash="+ games[gameUuid]["hash"])
if r.status_code == 200:
gameData["timeline"] = json.loads(r.text)
with open("./games/"+gameUuid+".json","w") as file:
file.write(json.dumps(gameData))
else:
print("Game "+gameUuid+" code error: "+str( r.status_code))
except:#for games ongoing
pass