Created
March 15, 2010 15:12
-
-
Save mwunsch/332925 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env ruby | |
## TumblrPurge: Destroy everything. | |
## | |
## *************WARNING************* | |
## | |
## USE THIS SCRIPT AT YOUR OWN RISK! | |
## I TAKE NO RESPONSIBILITY. | |
## | |
## This will destroy every Tumblr post. | |
## There is no undo. | |
## Backup before you do anything... | |
## | |
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 | |
deleted_count = 0 | |
ARGV.options do |option| | |
option.banner = "Usage: tumblrpurge [options] [name]" | |
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 purge') do |value| | |
blog = value | |
end | |
option.separator "" | |
option.parse! | |
end | |
if ARGV.first | |
blog = ARGV.first | |
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? | |
requests = posts.collect do |post| | |
req = post.delete(email, password) | |
req.on_complete do |resp| | |
if resp.success? | |
deleted_count += 1 | |
else | |
puts %Q(Error deleting post #{post.post_id}. Tumblr says #{resp.code}: "#{resp.message}") | |
end | |
end | |
req | |
end | |
else | |
abort 'No posts found.' | |
end | |
puts "Destroying all posts. Hold on to your butts..." | |
Weary.batch(requests).perform do | |
puts "Successfully deleted #{deleted_count} posts." | |
end | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment