$LOAD_PATH.unshift(__dir__ + "/../lib") require "rubygems" require "ap" require "lol" module Lol class Scraper attr_accessor :req, :client, :redis, :seed_id def get_summoner_id summoner self.req += 1 client.summoner.by_name(summoner).first.id end def get_leagues summoner_id self.req +=1 client.league.get summoner_id end def get_league_players summoner_id get_leagues(summoner_id).map do |l| l.entries.map do |entry| if entry.player_or_team_id.to_i == 0 nil else entry.player_or_team_id end end end.flatten.compact end def scrape_solo_league_for_teams summoner_id get_league_players(summoner_id).map do |player| if req >= 500 puts "Dormo per un minuto..." sleep(60) self.req = 0 end begin puts "#{req}. #{player}" if redis.sismember "losers", player nil else redis.sadd "winners", player self.req += 1 client.team.get player end rescue Lol::NotFound puts "Hitting the API on 404 - No cache" redis.sadd "losers", player nil rescue Lol::InvalidAPIResponse puts "Hit Rate Limit on #{player}" sleep(5) nil end end.compact.flatten end def get_players_from_leagues summoner_id begin scrape_solo_league_for_teams(summoner_id).map do |t| t.roster.member_list.map do |s| s.player_id end end.flatten.uniq rescue NoMethodError [] rescue Lol::NotFound [] end end def filter_captains redis.smembers("winners").each do |winner| ap winner begin team = client.team.get(winner) rescue Lol::NotFound next rescue Lol::InvalidAPIResponse puts "wait..." sleep(5) next end team.each do |t| if t.roster.owner_id == winner.to_i redis.sadd "captains", winner end end end end def get_captains puts redis.smembers("captains").sort end def initialize seed @req = 0 @client = Client.new ENV["RIOT_GAMES_API_KEY"], region: "euw", redis: "redis://localhost:6379", ttl: 36000 @redis = Redis.new @seed_id = get_summoner_id seed end end end # lotsa = scrape_league(get_summoner("intinig")).map do |player| # player.map do |team| # team.roster.member_list.map(&:player_id) # end.flatten # end.flatten.uniq # so_many = [] # lotsa.each do |summoner| # next if @redis.sismember("winners", summoner) # ap get_players(summoner) # so_many << scrape_league(summoner).map do |player| # player.map do |team| # team.roster.member_list.map(&:player_id) # end.flatten # end.flatten # end # ap so_many scraper = Lol::Scraper.new "intinig" scraper.get_captains # scraper.get_players_from_leagues(scraper.seed_id).map do |player| # begin # player = scraper.client.summoner.get(player).first.id # scraper.get_players_from_leagues(player) # rescue Lol::InvalidAPIResponse # sleep(2) # end # end