Created
December 31, 2008 07:50
-
-
Save hagmonk/41922 to your computer and use it in GitHub Desktop.
A dumb little script to analyze your twitter followers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
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(page=1) | |
url = "http://twitter.com/statuses/followers.xml?page=#{page}" | |
doc = self._get_doc_for_url(url) | |
followers = doc.search("users user").map { |u| u.at("screen_name").inner_text } | |
if followers.length == 100 | |
followers += self.followers(page+1) | |
end | |
return followers | |
end | |
def friends(page=1) | |
url = "http://twitter.com/statuses/friends.xml?page=#{page}" | |
doc = self._get_doc_for_url(url) | |
friends = doc.search("users user").map { |u| u.at("screen_name").inner_text } | |
if friends.length == 100 | |
friends += self.friends(page+1) | |
end | |
return friends | |
end | |
def repliers(page=1) | |
return [] if page > 5 | |
url = "http://twitter.com/statuses/replies.xml?page=#{page}" | |
doc = self._get_doc_for_url(url) | |
repliers = doc.search("statuses status user").map { |u| u.at("screen_name").inner_text } | |
if repliers.length == 20 | |
repliers += self.repliers(page+1) | |
end | |
return repliers | |
end | |
end | |
f = Twitter.new("your username", "your password") | |
followers = f.followers | |
friends = f.friends | |
repliers = f.repliers | |
unreciprocated = friends - followers | |
groupies = followers - friends | |
tentative_unrepentant_unreciprocators = unreciprocated - repliers | |
unreciprocated_but_thinking_of_you = repliers & unreciprocated | |
puts "UNRECIPROCATED" | |
puts "--------------" | |
p unreciprocated | |
puts "\n" | |
puts "TENTATIVE UNREPENTANT UNRECIPROCATORS" | |
puts "-------------------------------------" | |
p tentative_unrepentant_unreciprocators | |
puts "\n" | |
puts "UNRECIPROCATED BUT THINKING OF YOU" | |
puts "----------------------------------" | |
p unreciprocated_but_thinking_of_you | |
puts "\n" | |
puts "GROUPIES" | |
puts "--------" | |
p groupies | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment