Created
May 9, 2009 18:23
-
-
Save cxx/109367 to your computer and use it in GitHub Desktop.
privatize all published photos on Tumblr
This file contains hidden or 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/ruby | |
require 'open-uri' | |
require 'rexml/document' | |
user = '' | |
total = open("http://#{user}.tumblr.com/api/read?type=photo&num=0") do |f| | |
doc = REXML::Document.new(f) | |
REXML::XPath.first(doc, '//posts/@total').value.to_i | |
end | |
posts_per_page = 50 | |
0.step(total-1, posts_per_page) do |start| | |
open("http://#{user}.tumblr.com/api/read?type=photo&start=#{start}&num=#{posts_per_page}") do |f| | |
doc = REXML::Document.new(f) | |
REXML::XPath.each(doc, '//post/@id') {|id| puts id } | |
end | |
sleep(1) | |
end |
This file contains hidden or 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/ruby | |
require 'rubygems' | |
require 'mechanize' | |
email = '' | |
password = '' | |
max = ARGV[0] ? ARGV[0].to_i : 1.0/0.0 | |
agent = WWW::Mechanize.new | |
agent.get('http://www.tumblr.com/login').form_with(:action => '/login') do |form| | |
form['email'] = email | |
form['password'] = password | |
form.submit | |
end | |
$stdin.each do |line| | |
next if line.to_i > max | |
puts line | |
agent.get("http://www.tumblr.com/edit/#{line.chomp}").form_with(:action => %r{^/edit/}) do |form| | |
form['post[state]'] = 'private' | |
form.submit | |
end | |
sleep(1) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment