Class: OJAgent::LiveArchiveAgent
- 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
Instance Method Summary collapse
-
#initialize ⇒ LiveArchiveAgent
constructor
A new instance of LiveArchiveAgent.
- #login(user, pass) ⇒ Object
- #status(id) ⇒ Object
- #submit(pid, code, lang) ⇒ Object
Methods included from OJAgent
Constructor Details
#initialize ⇒ LiveArchiveAgent
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 login(user, pass) @user = user page = get '/' login_form = page.form_with :id => 'mod_loginform' login_form.set_fields :username => user, :passwd => pass login_form.checkbox_with(:name => 'remember').check result = login_form.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.( :name => 'language', :value => languages[lang]).check result = submit_form.submit = result / '.maincontent div.message' if && .inner_text =~ /Submission received with ID (\d+)/ $1 else nil end end |