require 'rspec'
require 'twitter'
class TwitterUser
def initialize()
@twitter = Twitter.new
end
def get_user(user_name)
begin
return @twitter.user(user_name)
rescue
end
end
def get_following(user_name)
begin
return @twitter.friend_ids(user_name)
rescue
end
end
def get_followers(user_name)
begin
return @twitter.follower_ids(user_name)
rescue
end
end
end
class TwitterCrawler
def initialize(start_user)
@twitter_user = TwitterUser.new
@start_user_id = Twitter.user(start_user)["id"]
end
def following_relation
@relation_array = Array.new
@following_ids = @twitter_user.get_following(@start_user_id)["ids"]
@following_ids.map{|id|
@relation_array << [@start_user_id,id]
}
end
end
array = TwitterCrawler.new("onodes").following_relation[0]
f = File.open("following.dat","w")
array.each{|id_list|
begin
TwitterCrawler.new(id_list[1]).following_relation[0].map{|ids|
f.puts(ids[0].to_s + " " + ids[1].to_s)
}
rescue
next
end
}
f.close
#p TwitterCrawler.new.get_user("onodes")
#p TwitterCrawler.new.get_followers("onodes")
describe do
before do
@twitter = TwitterUser.new.should be_true
end
it do
@twitter.get_user("onodes").should be_true
end
it do
@twitter.get_user(17942457).should be_true
end
it do
@twitter.get_user("onodes").should eq @twitter.get_user(17942457)
end
end