Skip to content

Instantly share code, notes, and snippets.

@DRMacIver
Created May 29, 2009 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save DRMacIver/120179 to your computer and use it in GitHub Desktop.
Save DRMacIver/120179 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
# Trivial little twitter script
# Pass it a list of names as command line arguments
# and it will return a list of all people who follow everyone in the
# list.
# A person is implicitly assumed to follow themselves, so if foo follows
# bar and bar follows foo then common_followers foo bar would include
# both foo and bar in the output, but if bar did not follow foo it
# would include neither.
require "rubygems"
require "httparty"
class Twitter
include HTTParty
base_uri "http://twitter.com"
format :json
def self.follower_ids(user)
get "/followers/ids/#{user}.json"
end
def self.username_for_id(user)
details(user)["screen_name"]
end
def self.id_for_username(user)
details(user)["id"]
end
def self.details(user)
(get "/users/show.json", :query => { :id => user })
end
end
require "set"
intersection = nil;
if __FILE__ == $0
ARGV.each do |user|
followers = Set[*Twitter.follower_ids(user)]
id = Twitter.id_for_username(user)
followers.add id
if !intersection
intersection = followers
else
intersection &= followers
end
end
intersection.each do |user|
puts Twitter.username_for_id(user)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment