Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- require 'rubygems'
- require 'net/http'
- require 'json'
- http = Net::HTTP.new('stream.twitter.com', 80)
- get = Net::HTTP::Get.new("/1/statuses/filter.json?track=awesome")
- get.basic_auth ARGV[0], ARGV[1]
- http.request(get) do |response|
- text = ""
- response.read_body do |chunk|
- chunk.each_byte do |c|
- if c == 10
- if text.length > 1
- begin
- json = JSON.parse(text)
- puts "#{json['user']['screen_name']}: #{json['text']}"
- rescue Exception => e
- puts "Unable to parse JSON:: #{e}"
- end
- text = ""
- end
- text = ""
- else
- text += c.chr
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment