Module: AtCoderFriends::Scraping::Submission

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

Overview

submit sources on submit page

Instance Method Summary collapse

Instance Method Details

#post_submit(q, langs, src) ⇒ Object



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

def post_submit(q, langs, src)
  page = fetch_with_auth(contest_url('submit'))
  lang = find_lang(page, langs)
  form = page.forms[1]
  form.field_with(name: 'data.TaskScreenName') do |sel|
    option = sel.options.find { |op| op.text =~ /\A#{q}\W/ }
    option&.select || (raise AppError, "unknown problem:#{q}.")
  end
  form.add_field!('data.LanguageId', lang)
  form.field_with(name: 'sourceCode').value = src
  form.submit
end

#submitObject



7
8
9
10
11
12
13
14
# File 'lib/at_coder_friends/scraping/submission.rb', line 7

def submit
  path, _dir, prg, _base, ext, q = ctx.path_info.components
  puts "***** submit #{prg} *****"
  langs = lang_id(ext)
  src = File.read(path, encoding: Encoding::UTF_8)

  post_submit(q, langs, src)
end