Skip to content

Instantly share code, notes, and snippets.

@kayakaya
Created August 21, 2009 16:19
Show Gist options
  • Save kayakaya/172154 to your computer and use it in GitHub Desktop.
Save kayakaya/172154 to your computer and use it in GitHub Desktop.
Download Twitter friends and followers by Ruby
#!/usr/bin/env ruby
require 'rubygems'
require 'twitter'
require 'cgi'
username = ''
password = ''
def create_client(username, password)
httpauth = Twitter::HTTPAuth.new(username, password)
client = Twitter::Base.new(httpauth)
return client
end
def get_users(client, type)
page = 1
open(type, "w") do |f|
while true
case type
when "friends" then users = client.friends(:page => page)
when "followers" then users = client.followers(:page => page)
end
break unless users.size > 0
users.each do |user|
f.puts(CGI.unescapeHTML("#{user.screen_name},#{user.name},#{user.url},#{(user.description)}"))
end
page = page + 1
end
end
end
if $0 == __FILE__
client = create_client(username, password)
get_users(client, "friends")
get_users(client, "followers")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment