Guest User

Untitled

a guest
Mar 14th, 2018
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. require 'net/http'
  2. require 'rubygems'
  3. require 'xmlsimple'
  4. require 'ruby-growl'
  5.  
  6. @email = 'jubishop@gmail.com'
  7. @password = 'Am4d3us'
  8. @intraDelay = 4
  9. @delay = 60
  10.  
  11. def fetch_timeline
  12. path = "/statuses/friends_timeline.xml"
  13. headers = { "User-Agent" => @email }
  14.  
  15. begin
  16. response = Net::HTTP.start('twitter.com', 80) do |http|
  17. req = Net::HTTP::Get.new(path, headers)
  18. req.basic_auth(@email, @password)
  19. http.request(req)
  20. end
  21.  
  22. return response.body
  23. rescue Exception
  24. return nil
  25. end
  26. end
  27.  
  28. growl = Growl.new("127.0.0.1", "squawk", ["squawk notification"])
  29. users = Hash.new
  30.  
  31. @first = true
  32. loop {
  33. xml = fetch_timeline
  34. unless xml.nil?
  35. doc = XmlSimple.xml_in(xml)
  36. doc['status'].reverse_each { |status|
  37. next unless status['user']
  38. id = status['id']
  39. user = status['user'].first['name'].to_s
  40. users[user] ||= Array.new
  41. next if (users[user].include?(id))
  42. users[user].push(id)
  43. text = status['text'].to_s
  44. growl.notify("squawk notification", user, text)
  45. sleep(@intraDelay) unless @first
  46. }
  47. end
  48. @first = false
  49. sleep(@delay)
  50. }
Add Comment
Please, Sign In to add comment