Skip to content

Instantly share code, notes, and snippets.

@ucnv
Forked from youpy/grope_shindanmaker.rb
Created June 5, 2011 22:51
Show Gist options
  • Save ucnv/1009511 to your computer and use it in GitHub Desktop.
Save ucnv/1009511 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'ubygems'
require 'grope'
require 'RMagick'
class Grope::WSOWrapper
def undefined?
@wso.class.to_s == 'OSX::WebUndefined'
end
end
@retried = 0
def make_shindan(result)
env = Grope::Env.new
env.load('http://shindanmaker.com/c/make')
env.wait
doc = env.document
doc.getElementById('pd[posttitle]').value = Time.new.to_i.to_s
doc.getElementById('pd[postdesc]').value = result
doc.getElementById('pd[postresult]').value = '[RESULT1]'
env.find('//textarea[@name="pd[postlist1]"]').value = result
env.capture(env.find('//img[starts-with(@src, "/c/image")]'), '/tmp/xxx.png')
img = Magick::Image.read('/tmp/xxx.png').first
img.resize!(5)
img = img.threshold(Magick::QuantumRange * 0.65)
img = img.deskew(0.40)
img.write('/tmp/xxx.pgm')
captcha = `ocrad /tmp/xxx.pgm`
captcha.gsub!(/[^a-zA-Z0-9]/, '')
env.find('//input[@name="image_key"]').value = captcha
env.find('//input[@type="submit"]').click
env.wait(1)
if env.find('//input[@name="1"]').undefined?
@retried += 1
exit(1) if @retried > 5
make_shindan(result)
else
env.all('//input[@name="pd[posttitle]"]').each do |e|
e.value = result
end
env.all('//input[@type="submit"]')[1].click
env.wait
env.document.body.innerHTML.match(/http:\/\/shindanmaker\.com\/\d+/)[0]
end
end
def tweet(id, password, status)
env = Grope::Env.new
env.load('http://twitter.com/intent/tweet?text=' + CGI.escape(status))
env.wait
doc = env.document
doc.getElementById('username_or_email').value = id
doc.getElementById('password').value = password
doc.getElementById('login-form').submit
env.wait(5)
env.document.getElementById('update-form').submit
env.wait
end
def main
status, id, password = ARGV
tweet(id, password, [status, make_shindan(status)].join(' '))
end
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment