module AtCoderFriends::Scraping::Tasks

fetch problems from tasks page

Public Instance Methods

fetch_all() { |pbm| ... } click to toggle source
# File lib/at_coder_friends/scraping/tasks.rb, line 7
def fetch_all
  puts "***** fetch_all #{contest} *****"
  fetch_assignments.map do |q, url|
    begin
      pbm = fetch_problem(q, url)
      yield pbm if block_given?
      pbm
    rescue StandardError => e
      puts e.to_s
      puts e.backtrace
    end
  end
end
fetch_assignments() click to toggle source
# File lib/at_coder_friends/scraping/tasks.rb, line 21
def fetch_assignments
  url = contest_url('tasks')
  puts "fetch list from #{url} ..."
  page = fetch_with_auth(url)
  page
    .search('//table[1]//td[1]//a')
    .each_with_object({}) do |a, h|
      h[a.text] = a[:href]
    end
end
fetch_problem(q, url) click to toggle source
# File lib/at_coder_friends/scraping/tasks.rb, line 32
def fetch_problem(q, url)
  puts "fetch problem from #{url} ..."
  page = fetch_with_auth(url)
  page.search('br').each { |br| br.replace("\n") }
  Problem.new(q, page)
end