Skip to content

Instantly share code, notes, and snippets.

@mmb
Created January 20, 2009 03:48
Show Gist options
  • Save mmb/49311 to your computer and use it in GitHub Desktop.
Save mmb/49311 to your computer and use it in GitHub Desktop.
imageshack uploader
#!/usr/bin/ruby
# upload a local image or an image on the web to imageshack
require 'rubygems'
require 'mechanize'
require 'open-uri'
require 'uri'
# upload an image to imageshack and return the imageshack url
# input can be a local image file path or an image url
def imageshack_upload(img)
img_io = open(img)
img_name = URI.parse(img).path
a = WWW::Mechanize.new
page = a.get('http://imageshack.us/')
upform = WWW::Mechanize::Form.new(page.search("//form[@id='upform']").first)
upform.checkbox_with(:name => 'rembar').check
fileupload = upform.file_uploads.first
fileupload.file_data = img_io
fileupload.file_name = img_name
response = a.submit(upform)
forum1 = response.search(
"//div[@id='forum1']/table/tr/td[1]/input").first['value']
forum1.match('\[IMG\](.*)\[/IMG\]')[1]
end
puts imageshack_upload(ARGV[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment