Skip to content

Instantly share code, notes, and snippets.

@tamalw
Created February 6, 2009 02:00
Show Gist options
  • Save tamalw/59170 to your computer and use it in GitHub Desktop.
Save tamalw/59170 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Written by @tamalw for @jasonfried (http://twitter.com/jasonfried/status/1177797820)
# Portions of the Twitter class borrowed from @hagus (http://gist.github.com/41922)
require 'rubygems'
require 'net/http'
require 'hpricot'
class Twitter
def initialize(username, password)
@http = Net::HTTP.start('twitter.com')
@username = username
@password = password
end
def _get_doc_for_url(url)
url = URI.parse(url)
req = Net::HTTP::Get.new(url.request_uri)
req.basic_auth(@username, @password)
res = @http.request(req)
return Hpricot.XML(res.body)
end
def followers_ids(username=@username)
url = "http://twitter.com/followers/ids/#{username}.xml"
doc = self._get_doc_for_url(url)
followers = doc.search("ids id").collect { |u| u.inner_text }
return followers
end
end
f = Twitter.new("your username", "your password")
first_username = "jasonfried"
second_username = "37signals"
first_followers = f.followers_ids(first_username)
second_followers = f.followers_ids(second_username)
overlap_followers = first_followers & second_followers
puts "Twitter follower comparison"
puts "---------------------------"
puts "#{first_username}: #{overlap_followers.size.to_f/first_followers.size*100}% overlap with #{second_username}"
puts "#{second_username}: #{overlap_followers.size.to_f/second_followers.size*100}% overlap with #{first_username}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment