Have any basic idea of OOP? No? Then, don’t bother reading.
Twitter is a place to have fun, stay updated and connect with friends of friends. Growing your network on Twitter now is becoming a little tougher than earlier. All thanks to bots and spammer
You know, they are the spoilsports found everywhere.
Anyways, I found something interesting on Jerod Santo’s blog. A way to expand you Twitter network with Ruby. This Ruby (program) generates a list of people highly followed by our friends.
The Flow
- Fetch the ids of all the people you follow
- Use those ids to fetch the ids of all the people they follow
- Remove any ids in both groups
- Tally the occurrences of each unique id in the list
- Sort them by most occurrences
- Iterate the top 10 and print the user information
The Script
require 'rubygems'
require 'twitter'
base = Twitter::Base.new(Twitter::HTTPAuth.new('username', 'password'))
my_friends = base.friend_ids
candidates = my_friends.inject(Array.new) { |array,id| array += Twitter.friend_ids(id); array }
candidates -= my_friends
tallied = candidates.inject(Hash.new(0)) { |hash, can| hash[can] += 1; hash }
ordered = tallied.sort { |x,y| y[1] <=> x[1] }
ordered[0..9].each do |array|
user = base.user(array[0])
puts "#{user.screen_name} is followed by #{array[1]} of the people you follow."
end
P.S I am not a Ruby programmer.
P.S.S You can follow me on Twitter. Click here here to do so.
Glad you liked my Ruby script! If you enjoyed that one, you might also want to check out this script with a similar purpose:
See Which Twitterers Don’t Follow You Back With Ruby