Created
March 15, 2010 03:09
-
-
Save ssig33/332453 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 "uri" | |
require "net/http" | |
require "rubygems" | |
require "json" | |
USERNAME = '' | |
PASSWORD = '' | |
uri = URI.parse('http://stream.twitter.com/1/statuses/filter.json') | |
Net::HTTP.start(uri.host, uri.port) do |http| | |
request = Net::HTTP::Post.new(uri.request_uri) | |
request.set_form_data('track' => ARGV[0]) | |
request.basic_auth(USERNAME, PASSWORD) | |
http.request(request) do |response| | |
response.read_body do |chunk| | |
status = JSON.parse(chunk) rescue next | |
next unless status['text'] | |
user = status['user'] | |
puts "#{user['screen_name']}: #{status['text']}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment