TumblrのFollowingを全消しするrubyスクリプト
11月 4th, 2008 by waku
http://d.hatena.ne.jp/Constellation/20081008/1223482383
を参考に
RUBY:
-
#!/usr/bin/ruby
-
require 'rubygems'
-
require 'mechanize'
-
require 'cgi'
-
-
email = ''
-
password = ''
-
-
module Tumblr
-
class Dashboard
-
PREFIX = 'http://www.tumblr.com/dashboard/iframe?src='
-
attr_reader :followers, :followings
-
def initialize(email, password)
-
@email = email
-
@password = password
-
@agent = WWW::Mechanize.new
-
login
-
end
-
-
def login
-
doc = @agent.get('http://www.tumblr.com/login')
-
form = doc.forms.first
-
form.email = @email
-
form.password = @password
-
@agent.submit(form)
-
end
-
-
def logout
-
@agent.get('http://www.tumblr.com/logout')
-
end
-
-
def get_followers
-
doc = @agent.get('http://www.tumblr.com/followers')
-
@followers = doc.search('.username')
-
end
-
-
def get_followings
-
doc = @agent.get('http://www.tumblr.com/following')
-
@followings = doc.search('.username')
-
end
-
-
def check
-
get_followers
-
get_followings
-
t_followings = @followings.collect {|a| a.inner_text }.sort
-
checked_users = Array.new
-
@followers.each do |a|
-
(t_followings.index(a.inner_text) == nil) && checked_users.push(a)
-
end
-
puts("follow #{checked_users.length} users")
-
num = 1
-
checked_users.each do |a|
-
print("#{a.inner_text}...")
-
doc = @agent.get(PREFIX+CGI.escape(a.attributes['href']))
-
form = doc.forms.first
-
form && @agent.submit(form)
-
puts("done")
-
end
-
logout
-
end
-
-
def delete_following
-
get_followings
-
t_followings = @followings.collect {|a| a.inner_text }.sort
-
puts("follow #{t_followings.length} users")
-
num = 1
-
@followings.each do |a|
-
print("#{a.inner_text}...")
-
doc = @agent.get(PREFIX+CGI.escape(a.attributes['href']))
-
form = doc.forms.first
-
form && @agent.submit(form)
-
puts("done")
-
end
-
logout
-
end
-
end
-
end
-
-
dashboard = Tumblr::Dashboard.new(email, password)
-
dashboard.delete_following






