Module: AtCoderFriends::Scraping::CustomTest
Overview
run tests on custom_test 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
#check_custom_test ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/at_coder_friends/scraping/custom_test.rb', line 38 def check_custom_test 100.times do page = agent.get(contest_url('custom_test/json?reload=true')) data = JSON.parse(page.body) return nil unless data.is_a?(Hash) && data['Result'] return data if data.dig('Result', 'Status') == 3 return data unless data['Interval'] sleep 1.0 * data['Interval'] / 1000 end nil end |
#code_test(infile) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/at_coder_friends/scraping/custom_test.rb', line 11 def code_test(infile) path, _dir, _prg, _base, ext, _q = split_prg_path(ctx.path) lang = lang_id(ext) src = File.read(path, encoding: Encoding::UTF_8) data = File.read(infile) post_custom_test(lang, src, data) check_custom_test end |
#post_custom_test(lang, src, data) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/at_coder_friends/scraping/custom_test.rb', line 21 def post_custom_test(lang, src, data) page = fetch_with_auth(contest_url('custom_test')) script = page.search('script').text csrf_token = script.scan(/var csrfToken = "(.*)"/)[0][0] page = agent.post( contest_url('custom_test/submit/json'), 'data.LanguageId' => lang, 'sourceCode' => src, 'input' => data, 'csrf_token' => csrf_token ) msg = page.body raise AppError, msg unless msg.empty? end |