Skip to content

Instantly share code, notes, and snippets.

@jmcph4
Created March 6, 2015 07:02
Show Gist options
  • Select an option

  • Save jmcph4/4c8a947d4cde6aa53eed to your computer and use it in GitHub Desktop.

Select an option

Save jmcph4/4c8a947d4cde6aa53eed to your computer and use it in GitHub Desktop.
Basic proof-of-concept code for a League of Legends team analyser.
require 'rubygems'
require 'json'
require 'open-uri'
API_KEY = "INSERT_API_KEY_HERE"
#API_ROOT = "https://oce.api.pvp.net/api/lol/oce/v1.3/"
def pull(id, type)
if id != nil
case type
when 'summary'
url = "https://oce.api.pvp.net/api/lol/oce/v1.3/stats/by-summoner/"+id.chomp+"/summary?api_key="+API_KEY
puts "Pulling summary for #{id.chomp}..."
when 'history'
url = "https://oce.api.pvp.net/api/lol/oce/v2.2/matchhistory/"+id.chomp+"?api_key="+API_KEY+"&beginIndex=0&endIndex=15" # API enforces a 15 game maximum
puts "Pulling history for #{id.chomp}..."
end
return data = open(URI.encode(url)).read
end
end
def parse(data)
#return tree = JSON.parse(data)
return tree = JSON.parse(data)
end
def print_summaries(summaries)
summoners.each do |s|
s.each do |t|
if t.respond_to?(:keys) == true
#puts "Keys: #{t.keys}"
puts "\nDisplaying information for #{t['summonerId']}:\n"
t["playerStatSummaries"].each do |stat|
if stat.respond_to?(:keys) == true
#puts stat.keys
puts " For the game type #{stat['playerStatSummaryType']}:"
puts " #{stat['wins']} wins with"
if stat["aggregatedStats"].respond_to?(:keys)
#puts "keys: #{stat['aggregatedStats'].keys}"
puts " #{stat["aggregatedStats"]["totalChampionKills"]} champion kills"
puts " #{stat["aggregatedStats"]["totalTurretsKilled"]} turret kills"
puts " #{stat["aggregatedStats"]["totalAssists"]} assists"
end
end
end
end
end
end
end
def print_performance(summaries, histories)
end
summaries = {}
histories = {}
File.readlines('input.txt').each do |id|
#stat summaries
summary = pull(id, "summary")
summaries[id.chomp.to_i] = parse(summary)
File.open('stat/summaries/'+id.chomp+'.json', 'w') do |file|
file.write(summary)
end
# match history
history = pull(id, "history")
histories[id.chomp.to_i] = parse(history)
File.open('matchhistory/'+id.chomp+'.json', 'w') do |file|
file.write(history)
end
end
# display summaries
print_summaries(summaries)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment