Guest User

Untitled

a guest
Mar 8th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. require 'rubygems'
  2. require 'httparty'
  3. require 'activesupport'
  4. require 'pp'
  5.  
  6. # EDIT THESE VALUES
  7. uname = ""
  8. pass = ""
  9. threshold = 1.week.ago
  10.  
  11. class Twitter
  12. include HTTParty
  13. base_uri 'twitter.com'
  14.  
  15. def initialize(u, p)
  16. @auth = {:username => u, :password => p}
  17. end
  18.  
  19. def friends(page = 1)
  20. self.class.get("/friends/ids.json?page=#{page}", {:basic_auth => @auth})
  21. end
  22.  
  23. def friend(id)
  24. self.class.get("/users/show/#{id}.json", {:basic_auth => @auth})
  25. end
  26.  
  27. def unfollow(id)
  28. self.class.post("/friendships/destroy/#{id}.json", {:basic_auth => @auth})
  29. end
  30.  
  31. end
  32.  
  33. twitter = Twitter.new(uname,pass)
  34. friends = twitter.friends
  35.  
  36. friends.each do |id|
  37. friend = twitter.friend(id)
  38. last_updated_at = DateTime.parse(friend["status"]["created_at"])
  39. if last_updated_at < threshold
  40. twitter.unfollow(id)
  41. end
  42. end
Add Comment
Please, Sign In to add comment