枕を欹てて聴く

香炉峰の雪は簾を撥げて看る

Tumblrの自分をfollowしている人で, 自分がfollowしていない人を全員followする

check followersのgreasemonkeyがなぜか自分ところでは動かなかったので.
たぶん何回やってもできない人があると思うけど, それはもうもとのTumblrが閉鎖されている場合.
mechanizeでアクセスしまくる力押し.

#!/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
  end
end

dashboard = Tumblr::Dashboard.new(email, password)
dashboard.check

Tumblrのpostにタグ付けするRubyスクリプト - cxxの日記 - たんぶら部 - Tumblove -

404 Not Found
を参考に.