Skip to content

Instantly share code, notes, and snippets.

@alpicola
Created October 10, 2012 13:20
Show Gist options
  • Save alpicola/3865602 to your computer and use it in GitHub Desktop.
Save alpicola/3865602 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'thor'
require 'mechanize'
USER = ''
PASS = ''
class Report < Thor
desc 'submit src1 src2 ...', 'Submit code'
def submit(*srcs)
agent = Mechanize.new
login_page = agent.get('http://hagi.is.s.u-tokyo.ac.jp/rss/')
login_page.form_with(:method => 'POST') do |form|
form['account[user]'] = USER
form['account[password]'] = PASS
end.submit
list_page = agent.click(agent.page.link_with(:href => '/rss/tasks'))
srcs.each do |src|
report_id = File.basename(src, '.c').to_i.to_s
upload_page = agent.click(list_page.link_with(:text => report_id))
upload_page.form_with(:method => 'POST') do |form|
form.file_uploads.first.file_name = src
end.submit
sleep 5
result_page = agent.click(list_page.link_with(:href => '/rss/reports'))
result = result_page.at("//td[text()=#{report_id}]").next_element.text
puts "#{src}: #{result}"
end
end
desc 'exec src1 src2 ...', 'Execute code'
def exec(*srcs)
srcs.each do |src|
executable = File.basename(src, '.c') + '.o'
system "gcc #{src} -o #{executable} && ./#{executable}"
end
end
end
Report.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment