Created
December 16, 2009 15:39
-
-
Save raykrueger/257930 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment