Guest User

Untitled

a guest
Apr 7th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. #!/usr/bin/ruby
  2.  
  3. require 'rubygems'
  4. require 'rubytter'
  5. require 'yaml'
  6. require 'pit'
  7. require 'pp'
  8.  
  9. def toCsv(friends)
  10. open('friends.csv', 'w') do |f|
  11. friends.each do |user|
  12. f.puts "#{user.screen_name},#{user.id}, #{user.name}, #{user.description.to_s.gsub(/\r\n/,'')}"
  13. end
  14. end
  15.  
  16. end
  17.  
  18. def toYaml(friends)
  19. friends.to_yaml
  20. open('friends.yaml', 'w') do |f|
  21. YAML.dump(friends, f)
  22. end
  23. end
  24.  
  25. config = Pit.get("twitter")
  26. username = config['username']
  27. password = config['password']
  28.  
  29. client = Rubytter.new(username, password)
  30.  
  31. friends = Array.new
  32. last = nil
  33. begin
  34. last = client.friends(username, :cursor => last ? last.next_cursor : -1)
  35. friends.concat(last.users)
  36. rescue Timeout::Error, StandardError
  37. puts "print Timeout::Error, StandardError"
  38. break
  39. end until last.next_cursor == 0
  40. toYaml(friends)
  41. toCsv(friends)
Add Comment
Please, Sign In to add comment