フォローされてるか調べるスクリプト
テキトーにフォローしまくったは良いものの
むむむ、なんかこの人とは合わない気がするかも
なんてことがある。
でもすでにフォロー返しされちゃってるとリムーブするの気が引ける。
↓というわけで相手にフォローされてるか調べるスクリプト
■使い方
your_screen_name, your_passwordのところを書き換えて
引数で相手の名前を渡してあげます。
$ ./check_follower.rb screen_name
副作用として、フォローしてるのにフォローされてないことがわかると
ちょっと悲しい気持ちになれます。
check_follower.rb
#!/usr/local/bin/ruby # -*- coding: utf-8 -*- require 'net/http' require 'rexml/document' class Relationships attr_accessor :followed_by, :following def initialize @followed_by = @following = false end def following?; @followed_by; end def follower?; @following; end end class Friendships def initialize @http = Net::HTTP.new('api.twitter.com', 80) @my_screen_name = "your_screen_name" @my_password = "your_password" end def relationships(screen_name) path = "/1/friendships/show.xml?target_screen_name=#{screen_name}" req = Net::HTTP::Get.new(path) req.basic_auth(@my_screen_name, @my_password) parse_relationships @http.request(req) end def parse_relationships(res) rel = Relationships.new doc = REXML::Document.new(res.body) doc.each_element('relationship/target') do |e| following = e.elements['following'].text followed_by_me = e.elements['followed_by'].text rel.following = true if following == "true" rel.followed_by = true if followed_by_me == "true" end rel end end f = Friendships.new screen_name = ARGV[0] if f.relationships(screen_name).follower? puts "フォローされてます" elsif puts "フォローされてません" end