Created
June 29, 2011 04:39
-
-
Save autch/1053166 to your computer and use it in GitHub Desktop.
Twitter で相互followしているユーザを表示。Grackleが必要。
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/ruby | |
# | |
# gem install grackle | |
# | |
# ./check_fof.rb <your_twitter_screen_name> | |
# | |
$KCODE = 'u' | |
require 'rubygems' | |
require 'grackle' | |
module Grackle | |
class TwitterStruct | |
def eql?(other) | |
self.id == other.id | |
end | |
def hash | |
self.id | |
end | |
end | |
end | |
client = Grackle::Client.new() | |
def client.collect_users(what, identity) | |
cursor = -1 | |
users = [] | |
begin | |
result = self.statuses.send(what, { :cursor => cursor }.merge(identity)) | |
cursor = result.next_cursor | |
users += result.users | |
$stderr.print "#{users.count}..." | |
end while(cursor != 0) | |
users | |
end | |
screen_name = ARGV.shift || 'autch' | |
$stderr.print "Getting info for user #{screen_name}..." | |
my_info = client.users.show?(:screen_name => screen_name) | |
my_id = my_info.id | |
$stderr.print " => id #{my_id}\n" | |
$stderr.print "Collecting followers of id #{my_id}..." | |
my_followers = client.collect_users(:followers?, { :user_id => my_id }) | |
$stderr.print "done, #{my_followers.count} followers\n" | |
$stderr.print "Collecting friends of id #{my_id}..." | |
my_friends = client.collect_users(:friends?, { :user_id => my_id }) | |
$stderr.print "done, #{my_friends.count} friends\n" | |
fof = (my_followers & my_friends) | |
fof.each do |f| | |
print "#{f.name} (@#{f.screen_name}) #{f.url}\n" | |
print "#{f.description}\n" | |
print "\n" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment