Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'net/http'
- require 'rubygems'
- require 'xmlsimple'
- require 'ruby-growl'
- @email = 'jubishop@gmail.com'
- @password = 'Am4d3us'
- @intraDelay = 4
- @delay = 60
- def fetch_timeline
- path = "/statuses/friends_timeline.xml"
- headers = { "User-Agent" => @email }
- begin
- response = Net::HTTP.start('twitter.com', 80) do |http|
- req = Net::HTTP::Get.new(path, headers)
- req.basic_auth(@email, @password)
- http.request(req)
- end
- return response.body
- rescue Exception
- return nil
- end
- end
- growl = Growl.new("127.0.0.1", "squawk", ["squawk notification"])
- users = Hash.new
- @first = true
- loop {
- xml = fetch_timeline
- unless xml.nil?
- doc = XmlSimple.xml_in(xml)
- doc['status'].reverse_each { |status|
- next unless status['user']
- id = status['id']
- user = status['user'].first['name'].to_s
- users[user] ||= Array.new
- next if (users[user].include?(id))
- users[user].push(id)
- text = status['text'].to_s
- growl.notify("squawk notification", user, text)
- sleep(@intraDelay) unless @first
- }
- end
- @first = false
- sleep(@delay)
- }
Add Comment
Please, Sign In to add comment