Skip to content

Instantly share code, notes, and snippets.

@yoko
Created January 22, 2010 10:38
Show Gist options
  • Save yoko/283675 to your computer and use it in GitHub Desktop.
Save yoko/283675 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'httpclient'
require 'pit'
def growl(title, message, options = {})
arg = ''
options.each {|k, v| arg << " --#{k}" + (v == true ? '' : " \"#{v}\"") }
`/usr/local/bin/growlnotify -t "#{title}" -m "#{message}"#{arg}`
end
config = Pit.get('tumblr', :require => {
'email' => 'Tumblr email',
'password' => 'Tumblr password',
})
http = HTTPClient.new
ARGV.each do |filename|
(dirname, basename) = File::split(filename)
open(filename) do |file|
r = http.post('http://www.tumblr.com/api/write', {
'email' => config['email'],
'password' => config['password'],
'type' => 'photo',
'data' => file,
})
message = "#{r.status} #{r.content}"
p message
if r.status == 201
title = 'Post to Tumblr successed'
message = "Tumblr post's ID is #{r.content}."
growl(title, message, { :image => filename })
File::rename(filename, "#{dirname}/#{r.content}_#{basename}")
else
title = 'Post to Tumblr failed'
growl(title, message, { :image => filename, :sticky => true })
exit
end
end
sleep 2
end
growl('Post to Tumblr completed', 'Posted all images.', { :appIcon => 'Tumblr Backup', :sticky => true })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment