Class: OJAgent::LiveArchiveAgent

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

Constant Summary collapse

@@selector =
'.maincontent table tr'
@@thead =
[:id, :pid, :pname, :status, :lang, :time, :data]

Constants included from OJAgent

StandardAgents, VERSION

Instance Method Summary collapse

Methods included from OJAgent

all

Constructor Details

#initializeLiveArchiveAgent

Returns a new instance of LiveArchiveAgent.



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

def initialize
  super 'http://icpcarchive.ecs.baylor.edu',
    :c      => '1',
    :java   => '2',
    :cpp    => '3',
    :pascal => '4'
end

Instance Method Details

#login(user, pass) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/ojagent/livearchive_agent.rb', line 11

def (user, pass)
  @user = user
  page = get '/'
   = page.form_with :id => 'mod_loginform'
  .set_fields :username => user,
                        :passwd   => pass
  .checkbox_with(:name => 'remember').check
  result = .submit
end

#status(id) ⇒ Object



42
43
44
45
46
47
# File 'lib/ojagent/livearchive_agent.rb', line 42

def status(id)
  url = '/index.php?option=com_onlinejudge&Itemid=9'
  parse_status url, @@selector, @@thead do |tr|
    !tr.empty? && tr[0].inner_text == id
  end
end

#submit(pid, code, lang) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ojagent/livearchive_agent.rb', line 21

def submit(pid, code, lang)
  page = get '/index.php?option=com_onlinejudge&Itemid=25'
  action = 'index.php?option=com_onlinejudge&Itemid=25&page=save_submission'
  submit_form = page.form_with :action => action
  submit_form.set_fields :localid  => pid,
                         :code     => code
  submit_form.radiobutton_with(
    :name => 'language', :value => languages[lang]).check
  result = submit_form.submit

  message = result / '.maincontent div.message'
  if message && message.inner_text =~ /Submission received with ID (\d+)/
    $1
  else
    nil
  end
end