Skip to content

Instantly share code, notes, and snippets.

@mwunsch
Created March 18, 2010 02:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mwunsch/335976 to your computer and use it in GitHub Desktop.
Save mwunsch/335976 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
## TumblrBak: Gets posts.
##
begin
require 'optparse'
require 'rubygems'
require 'tumblr'
require 'highline/import'
rescue LoadError
abort "Error: #{$!}. Make sure you `gem install tumblr-rb`"
end
email = nil
password = nil
blog = nil
saved_count = 0
ARGV.options do |option|
option.banner = "Usage: tumblrbak [options]"
option.separator ""
option.separator "Options"
auth_text = 'Email Address and Password, separated by a colon'
option.on('-a EMAIL:PASSWORD', '--auth EMAIL:PASSWORD', auth_text) do |auth|
email,password = auth.split(':')
end
option.on('--name=BLOG', 'Which blog to backup') do |value|
blog = value
end
option.separator ""
option.parse!
end
email = ask("Email Address: ") if !email
password = ask("Password: ") { |q| q.echo = false } if !password
blog = ask("Blog Name: ") if !blog
abort 'You need to provide an e-mail address.' if email.blank?
abort 'You need to provide a password.' if password.blank?
abort 'You need to provide a blog name.' if blog.blank?
puts 'Authenticating to Tumblr...'
Tumblr.new(email, password).authenticate.perform do |response|
if !response.success?
abort %Q(Oh no! Something went wrong. Tumblr said #{response.code}: "#{response.message}")
end
end
puts "Getting posts...this could take a while."
posts = Tumblr::Reader.new(email, password).get_all_posts(blog)
if !posts.blank?
posts.each do |post|
end
else
abort 'No posts found.'
end
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment