Skip to content

Instantly share code, notes, and snippets.

@intinig
Created January 20, 2015 14:32
Show Gist options
  • Save intinig/54149ecfd2efe4a9934c to your computer and use it in GitHub Desktop.
Save intinig/54149ecfd2efe4a9934c to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'lol'
require 'redis'
include Lol
client = Client.new "foo", {region: ENV['API_REGION']}
redis = Redis.new :url => ENV['REDIS_URL']
def fetch client, redis, slice
return -1 if redis.llen("players") >= 50000
c = client.summoner.get slice
results = c.select {|x| x.summoner_level == 30}.map {|y| h = "#{y.id},#{y.name}"; puts h; h}
redis.rpush("players", results) if results != []
end
threads = ThreadGroup.new
(ENV['START'].to_i .. ENV['END'].to_i).each_slice(40) do |p_ids|
sleep 1 while threads.list.size >= 100
thread = Thread.new { fetch client, redis, p_ids}
threads.add thread
thread.join
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment