Module: AtCoderFriends::Scraping::Submission

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

Overview

submit sources on submit page

Constant Summary

Constants included from PathUtil

PathUtil::CASES_DIR, PathUtil::SMP_DIR, PathUtil::TMP_DIR

Instance Method Summary collapse

Methods included from PathUtil

cases_dir, contest_name, makedirs_unless, smp_dir, split_prg_path, tmp_dir

Instance Method Details

#post_submit(q, lang, src) ⇒ Object



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

def post_submit(q, lang, src)
  page = fetch_with_auth(contest_url('submit'))
  form = page.forms[1]
  form.field_with(name: 'data.TaskScreenName') do |sel|
    option = sel.options.find { |op| op.text.start_with?(q) }
    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



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

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

  post_submit(q, lang, src)
end