Class: AtCoderVcFriends::Scraping::Agent

Inherits:
AtCoderFriends::Scraping::Agent
  • Object
show all
Defined in:
lib/at_coder_vc_friends/scraping/agent.rb

Overview

scraping agent for virtual contest

Instance Method Summary collapse

Instance Method Details

#fetch_all_vc(contest_url) ⇒ Object



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

def fetch_all_vc(contest_url)
  puts '***** fetch_all_vc *****'
  fetch_assignments_vc(contest_url).map do |pbm_url|
    pbm = fetch_problem_vc(pbm_url)
    yield pbm if block_given?
    pbm
  end
end

#fetch_assignments_vc(contest_url) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/at_coder_vc_friends/scraping/agent.rb', line 18

def fetch_assignments_vc(contest_url)
  puts "fetch list from #{contest_url} ..."
  page = agent.get(contest_url)
  page
    .search('//table[1]//thead//a')
    .map { |a| a[:href] }
end

#fetch_problem_vc(pbm_url) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/at_coder_vc_friends/scraping/agent.rb', line 26

def fetch_problem_vc(pbm_url)
  m = pbm_url.match('/contests/(?<contest>.+)/tasks/(?<task>.+)')
  contest = m[:contest]
  key = task_key(pbm_url)
  q = "#{contest}##{key}"
  fetch_problem(q, pbm_url)
end

#post_submit(q, lang, src) ⇒ Object



43
44
45
# File 'lib/at_coder_vc_friends/scraping/agent.rb', line 43

def post_submit(q, lang, src)
  super(q.split('#')[1], lang, src)
end

#task_key(pbm_url) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/at_coder_vc_friends/scraping/agent.rb', line 34

def task_key(pbm_url)
  tasks_url = File.dirname(pbm_url)
  page = fetch_with_auth(tasks_url)
  page
    .search('//table[1]//td[1]//a')
    .find { |a| pbm_url.end_with?(a[:href]) }
    .text
end