Created
August 19, 2012 01:26
-
-
Save zthomae/3390788 to your computer and use it in GitHub Desktop.
Get a "map" of your twitter followers for useful RTs - See which of your followers are following people that you also follow.
This file contains hidden or 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
| require "twitter" | |
| # Set sample size (pick this percentage of your followers) | |
| SAMPLE_SIZE = 0.25 | |
| # Construct Twitter instance | |
| t = Twitter.new | |
| # Add screenname to params | |
| screen_name = "zthomae" | |
| # Make hash of users screen_name follows, with a count set to zero. | |
| friends = Hash.new(0) | |
| t.friend_ids(screen_name).collection.each { |x| friends[x] = 0 } | |
| # Take a random sample of the users following screen_name, rounded up. | |
| # Discard result if a duplicate or if user is protected. | |
| # TODO?: Authentication (kicking out protected users is questionable) | |
| followers = t.follower_ids(screen_name).collection | |
| num = (followers.size * SAMPLE_SIZE).ceil | |
| sample = Array.new | |
| while sample.size < num | |
| follower = followers[rand(0..followers.size)] | |
| sample.push(follower) if (!sample.include?(follower) && !t.user(follower).protected?) | |
| end | |
| # For each of these users, get a list of all of the users they follow. | |
| # If they are in friends, increment their counter. | |
| sample.each do |x| | |
| f_friends = t.friend_ids(t.user(x)).collection | |
| f_friends.each do |y| | |
| friends[y] += 1 if !friends.include?(y) | |
| end | |
| end | |
| # Sort friends by counter value. Print final results. | |
| friends = friends.sort_by { |key, value| value } | |
| friends.each { |x| puts x.to_s } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment