Advertisement
Guest User

Untitled

a guest
Oct 28th, 2017
939
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. import requests, json
  2.  
  3. # leagueId=9 is for worlds, change at will
  4. urlTournament="http://api.lolesports.com/api/v1/scheduleItems?leagueId=9"
  5. r = requests.get(urlTournament)
  6. data = json.loads(r.text)
  7.  
  8. tournamentId = data['highlanderTournaments'][2]["id"]
  9.  
  10. brackets = data['highlanderTournaments'][2]["brackets"]
  11.  
  12. matches = []
  13. games = {}
  14.  
  15. #Get the list of matches and each of their games
  16. for bracketId in brackets:
  17. #print("Bracket : "+bracketId)
  18. bracket = brackets[bracketId]
  19.  
  20. for matchId in bracket["matches"]:
  21.  
  22. match = bracket["matches"][matchId]
  23. for gameId in match['games']:
  24.  
  25. game = match['games'][gameId]
  26.  
  27. if 'gameId' in game:
  28. matches.append(matchId)
  29. games[gameId] = {"matchHistoryId":game['gameId']}
  30.  
  31. #Call each match to get the game hash
  32. baseMatchUrl = "http://api.lolesports.com/api/v2/highlanderMatchDetails?tournamentId="+tournamentId+"&matchId="
  33. for matchId in matches:
  34. r = requests.get(baseMatchUrl + matchId)
  35. dataMatch = json.loads(r.text)
  36. for i in dataMatch["gameIdMappings"]:
  37. games[i["id"]]["hash"] = i["gameHash"]
  38.  
  39. #At last get the full game data
  40. baseMatchHistoryUrl = "https://acs.leagueoflegends.com/v1/stats/game/TRLH1/"
  41.  
  42. for gameId in games:
  43. r = requests.get(baseMatchHistoryUrl + games[gameId]["matchHistoryId"] + "?gameHash=" + games[gameId]["hash"])
  44. dataGame = json.loads(r.text)
  45.  
  46. r = requests.get(baseMatchHistoryUrl + games[gameId]["matchHistoryId"] + "/timeline?gameHash=" + games[gameId]["hash"])
  47. dataGame['timeline'] = json.loads(r.text)
  48.  
  49. print(dataGame)
  50.  
  51. break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement