fogus (owner)

Fork Of

Revisions

gist: 120303 Download_button fork
public
Public Clone URL: git://gist.github.com/120303.git
Embed All Files: show embed
common_followers #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/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
 
Text only #