Created
March 30, 2010 20:16
-
-
Save satyr/349539 to your computer and use it in GitHub Desktop.
caddyr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GOLF_DIR = File.join(ENV['HOME'], '.golf') | |
require 'pstore' | |
require 'caddy/db' | |
require 'net/http/multipart' | |
Net::HTTP.version_1_2 | |
@file = $*[0] | |
problem = $*[1] || file2problem(File.basename(@file, File.extname(@file))) | |
@data = { | |
'problem' => problem =~ /^http:\/\/golf.shinh.org\/p.rb\?/ && $', | |
'user' => get_user, | |
'reveal' => '1', | |
} | |
def submit | |
Net::HTTP.start('golf.shinh.org', 80) do |http| | |
req = Net::HTTP::Post.new('/submit.rb') | |
req.set_multipart_form_data({'file' => @file}, @data) | |
res = http.request(req) | |
if res.class.superclass != Net::HTTPSuccess | |
puts 'Failed to connect the golf server' | |
exit 1 | |
end | |
body = res.read_body | |
body.gsub!(/<[^>]*>/, '') | |
body | |
end | |
end | |
i = 0 | |
until /Success!.*?\n\n/m =~ r = submit | |
puts "#{i += 1}: #{r.scan(/(#\d)\nsuccess!/) * ' '}" | |
end | |
puts $& |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment