Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/ruby
- require 'rubygems'
- require 'rubytter'
- require 'yaml'
- require 'pit'
- require 'pp'
- def to_csv(users)
- open('friends.csv', 'w') do |f|
- uesrs.each do |user|
- f.puts "#{user.screen_name},#{user.id}, #{user.name}, #{user.description.to_s.gsub(/\r\n/,'')}"
- end
- end
- end
- def to_yaml(users, filename)
- users.to_yaml
- open(filename, 'w') do |f|
- YAML.dump(users, f)
- end
- end
- def get_friends(client, username)
- friends = Array.new
- last = nil
- begin
- last = client.friends(username, :cursor => last ? last.next_cursor : -1)
- friends.concat(last.users)
- rescue Timeout::Error, StandardError
- puts "print Timeout::Error, StandardError"
- break
- end until last.next_cursor == 0
- return friends
- end
- def get_followers(client, username)
- followers = Array.new
- last = nil
- begin
- last = client.followers(username, :cursor => last ? last.next_cursor : -1)
- followers.concat(last.users)
- rescue Timeout::Error, StandardError
- puts "print Timeout::Error, StandardError"
- break
- end until last.next_cursor == 0
- return followers
- end
- def create_client
- config = Pit.get("twitter")
- username = config['username']
- password = config['password']
- return Rubytter.new(username, password)
- end
- username = 'kayakaya'
- client = create_client
- to_yaml(get_friends(client, username), 'friends.yaml')
- to_yaml(get_followers(client, username), 'followers.yaml')
Add Comment
Please, Sign In to add comment