< Browse > Home / Programming, Twitter / Blog article: Expand Your Twitter Network With Ruby

| Mobile | RSS

July 11th, 2009

Expand Your Twitter Network With Ruby

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

  1. Fetch the ids of all the people you follow
  2. Use those ids to fetch the ids of all the people they follow
  3. Remove any ids in both groups
  4. Tally the occurrences of each unique id in the list
  5. Sort them by most occurrences
  6. 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. :)

Related Posts

Follow Discussion

2 Responses to “Expand Your Twitter Network With Ruby”

  1. Jerod Santo Says:

    Hi Joel-

    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

  2. Anoop Says:

    Hi, I was just browsing through all the partner’s pages whom i exchanged links with and found mine missing on yours. Tech-Hut (http://tech-hutblog.blogspot.com) Do you want to discontinue link exchange?

Leave a Reply