Class: OJAgent::TimusAgent

Inherits:
OJAgent
  • Object
show all
Defined in:
lib/ojagent/timus_agent.rb

Constant Summary collapse

@@selector =
'table.status tr'
@@thead =
[:id, :date, :user, :pname, :lang, :status, :testid, :time, :mem]

Constants included from OJAgent

StandardAgents, VERSION

Instance Method Summary collapse

Methods included from OJAgent

all

Constructor Details

#initializeTimusAgent

Returns a new instance of TimusAgent.



3
4
5
6
7
8
9
10
# File 'lib/ojagent/timus_agent.rb', line 3

def initialize
  super 'http://acm.timus.ru',
    :pascal => '3',
    :java   => '7',
    :c      => '9',
    :cpp    => '10',
    :cs     => '11'
end

Instance Method Details

#login(user, pass) ⇒ Object



12
13
14
15
# File 'lib/ojagent/timus_agent.rb', line 12

def (user, pass)
  @user = user
  @pass = pass
end

#status(pid) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/ojagent/timus_agent.rb', line 31

def status(pid)
  url = '/status.aspx?author=' + user
  status = parse_status url, @@selector, @@thead do |tr|
    tr[3] && tr[3].inner_text.start_with?(pid)
  end
  if status[:pname] =~ /^(\d+).\s*(.*)$/
    status[:pid], status[:pname] = $1, $2
  end
  status
end

#submit(pid, code, lang) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/ojagent/timus_agent.rb', line 17

def submit(pid, code, lang)
  page = get '/submit.aspx'
  submit_form = page.form_with :action => 'submit.aspx?space=1'
  submit_form.set_fields :JudgeID    => user + @pass,
                         :Language   => languages[lang],
                         :ProblemNum => pid,
                         :Source     => code
  submit_form.submit
  pid.to_s
end