Module: AtCoderFriends::Scraping::Tasks

Included in:
Agent
Defined in:
lib/at_coder_friends/scraping/tasks.rb

Overview

fetch problems from tasks page

Instance Method Summary collapse

Instance Method Details

#fetch_allObject



9
10
11
12
13
14
15
16
# File 'lib/at_coder_friends/scraping/tasks.rb', line 9

def fetch_all
  puts "***** fetch_all #{contest} *****"
  fetch_assignments.map do |q, url|
    pbm = fetch_problem(q, url)
    yield pbm if block_given?
    pbm
  end
end

#fetch_assignmentsObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/at_coder_friends/scraping/tasks.rb', line 18

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) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/at_coder_friends/scraping/tasks.rb', line 29

def fetch_problem(q, url)
  puts "fetch problem from #{url} ..."
  page = fetch_with_auth(url)
  Problem.new(q) do |pbm|
    page.search('br').each { |br| br.replace("\n") }
    pbm.page = page
  end
end