require 'yaml' require 'rubygems' require 'twitter' twit = Twitter::Base.new("username", "password") screen_name = ARGV[0] user = twit.user(screen_name) people = {} friend_map = {} friends = twit.friends_for(screen_name) friends.each do |friend| puts "*******************************************" puts "adding #{friend.name} to the list of people" people[friend.id] = friend if friend_map[friend.id] puts "already retrieved their friends" else puts "getting their friends\n******************************************" friend_map[friend.id] = [] begin twit.friends_for(friend.id).each do |f| unless people[f.id] puts "adding #{f.name} to the list of people" people[f.id] = f end friend_map[friend.id] << f.id end rescue => e puts e end puts "they had #{friend_map[friend.id].size} friends" end end File.open("#{screen_name}.yml", 'w') {|f| f.puts user.to_yaml} File.open("#{screen_name}-people.yml", 'w') {|f| f.puts people.to_yaml } File.open("#{screen_name}-friend_map.yml", 'w') {|f| f.puts friend_map.to_yaml } File.open("#{screen_name}-friends.yml", 'w') {|f| f.puts friends.to_yaml }