Skip to content

Instantly share code, notes, and snippets.

@damon
Created July 11, 2010 04:27
Show Gist options
  • Save damon/471278 to your computer and use it in GitHub Desktop.
Save damon/471278 to your computer and use it in GitHub Desktop.
who do I interact with most on Twitter?
#!/usr/bin/env ruby
require 'rubygems'
require 'grackle'
require 'pp'
STATUSES_MAX = 200
PAGE_MAX = 5
client = Grackle::Client.new
name = (ARGV[0] ? ARGV[0] : "damon")
puts "Who does #{name} interact with most?"
all_statuses = []
page = 1
while !(statuses = client.statuses.user_timeline? :screen_name=>name, :page => page, :count => STATUSES_MAX).nil? && page <=PAGE_MAX
all_statuses << statuses
page += 1
sleep 1
end
all_statuses.flatten!
interactors = {}
all_statuses.each do |status|
sn = status.in_reply_to_screen_name
if sn
interactors[sn] = (interactors[sn] ? 1 : interactors[sn] + 1)
end
end
result = []
interactors.each_pair do |k,v|
result << "#{v}-#{k}"
end
pp result.sort.reverse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment