Sha256: 35695e4731fee8d03e5160bef614d7e3938f3457c3e3e0c6c2470a9e53283b3d
Contents?: true
Size: 1.24 KB
Versions: 2
Compression:
Stored size: 1.24 KB
Contents
# frozen_string_literal: true require 'at_coder_friends' module AtCoderVcFriends module Scraping # scraping agent for virtual contest class Agent < AtCoderFriends::Scraping::Agent 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 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 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 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 def post_submit(q, lang, src) super(q.split('#')[1], lang, src) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
at_coder_vc_friends-0.1.1 | lib/at_coder_vc_friends/scraping/agent.rb |
at_coder_vc_friends-0.1.0 | lib/at_coder_vc_friends/scraping/agent.rb |