class OJS::Codeforces

Constants

LANGUAGE_ID

Public Class Methods

csrf_token() click to toggle source
# File lib/ojsubmitter/judge/codeforces.rb, line 90
def csrf_token
  unless @csrf_token
    res = hclient.get('http://codeforces.com')
    @csrf_token = Nokogiri::HTML.parse(res.body).xpath('/html/head/meta[@name="X-Csrf-Token"]/@content').to_s
  end
  @csrf_token
end
language() click to toggle source
# File lib/ojsubmitter/judge/codeforces.rb, line 76
def language
  LANGUAGE_ID[@config['language'].to_s.downcase]
end
login() click to toggle source
# File lib/ojsubmitter/judge/codeforces.rb, line 45
def login
  res = hclient.post(
    'http://codeforces.com/enter',
    { handle:     user,
      password:   password,
      action:     'enter',
      ftaa:       '',
      bfaa:       '',
      csrf_token: csrf_token,
    }
  )
  raise Judge::LoginFailedError if res.body =~ /(Invalid handle or password)|(Fill in the form to login into Codeforces.)/
  Logger.info "Logged in successfully."
end
post() click to toggle source
# File lib/ojsubmitter/judge/codeforces.rb, line 60
def post
  res = hclient.post(
    'http://codeforces.com/problemset/submit',
    { submittedProblemCode: problem_id,
      programTypeId:        language,
      source:               code,
      csrf_token:           csrf_token,
      action:               'submitSolutionFormSubmitted',
    }
  )
end
problem_id() click to toggle source
# File lib/ojsubmitter/judge/codeforces.rb, line 80
def problem_id
  unless @config['problem_id']
    @config['problem_id'] = File.basename(file).split('.')[0]
    unless @config['problem_id'] =~ /\d+/
      @config['problem_id'] = Dir.pwd.split('/').last + @config['problem_id']
    end
  end
  @config['problem_id'].to_s.upcase
end
status_url() click to toggle source
# File lib/ojsubmitter/judge/codeforces.rb, line 72
def status_url
  "http://codeforces.com/submissions/#{user}"
end