Advertisement
t_a_w

rankk best next challenges

Oct 29th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.91 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. require "httparty"
  4. require "nokogiri"
  5.  
  6. class ChallengesSolves
  7.   def initialize(user)
  8.     @user = user
  9.   end
  10.  
  11.   def solves
  12.     @solves ||= Pathname("#{__dir__}/rankk_solves.txt")
  13.       .readlines
  14.       .map(&:chomp)
  15.       .map{|line| line.split("\t")}
  16.       .map{|id, count| [id, count.to_i]}
  17.       .to_h
  18.   end
  19.  
  20.   def solved_by_user
  21.     @solved_by_user ||= begin
  22.       doc = Nokogiri::HTML(HTTParty.get("https://www.rankk.org/user/#{@user}"))
  23.       doc.css(".solved li").map{|li|
  24.         a, b = li.text[/\S+/].split("/")
  25.         "%d/%02d" % [a, b]
  26.       }
  27.     end
  28.   end
  29.  
  30.   def call
  31.     solves
  32.     solved_by_user
  33.     report = solves
  34.       .map{|id,count|
  35.         [-count, id, solved_by_user.include?(id) ? "DONE" : ""]
  36.       }
  37.       .sort
  38.       .map{|c,i,s| [-c,i,s] }
  39.     report.each do |row|
  40.       puts row.join("\t")
  41.     end
  42.   end
  43. end
  44.  
  45. ChallengesSolves.new("taw").call
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement