Skip to content

Instantly share code, notes, and snippets.

@machu
Created August 21, 2009 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save machu/172144 to your computer and use it in GitHub Desktop.
Save machu/172144 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'twitter'
def get_friends(twit, page = 1)
r = twit.friends(:page => page)
(r.size == 100) ? r.concat(get_friends(twit, page + 1)) : r
end
UID = 'your_twitter_id'
PASSWORD = 'your_twitter_password'
auth = Twitter::HTTPAuth.new(UID, PASSWORD)
twit = Twitter::Base.new(auth)
friends = get_friends(twit)
h = Hash.new(0)
open("friends.txt", "w") do |f|
friends.each do |friend|
if friend[:friends_count] > 0
rate = friend[:followers_count].to_f / friend[:friends_count].to_f
log = ("%.1f" % Math::log10(rate)).to_f
f.puts "#{'%.1f' % log} #{friend[:screen_name]} #{friend[:followers_count]} / #{friend[:friends_count]}"
h[log] += 1
end
end
end
open("data.csv", "w") do |f|
h.keys.sort.each {|key| f.puts "#{key},#{h[key]}" }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment