Created
September 17, 2011 20:24
-
-
Save tenderlove/1224329 to your computer and use it in GitHub Desktop.
This file contains 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
require 'thread' | |
require 'json' | |
require 'net/http' | |
require 'uri' | |
require 'betabrite' | |
require 'psych' | |
require 'usb' | |
class StreamClient | |
def initialize user, pass | |
@user = user | |
@pass = pass | |
end | |
def listen &block | |
uri = URI.parse("https://stream.twitter.com/1/statuses/filter.json") | |
producer = Thread.new do | |
http = Net::HTTP.new(uri.host, uri.port) | |
http.use_ssl = true | |
http.start do |http| | |
request = Net::HTTP::Post.new(uri.path) | |
request.basic_auth @user, @pass | |
request.set_form_data({:track=>"gogaruco"}, "&") | |
http.request(request) do |response| | |
response.read_body do |segment| | |
begin | |
block.call JSON.load(segment) | |
rescue JSON::ParserError | |
end | |
end | |
end | |
end | |
end | |
end | |
end | |
queue = Queue.new | |
StreamClient.new(*Psych.load_file(ARGV[0])).listen { |thing| | |
queue << thing | |
} | |
trap(:INT) do | |
queue.clear | |
end | |
Thread.new { | |
colors = [ 'FF0000', '00FF00', '0000FF', 'FFFF00', 'FF00FF', '00FFFF', | |
'FFFFFF', | |
] | |
while data = queue.pop | |
BetaBrite::USB.new { |sign| | |
sign.stringfile('0') do | |
print string("[@#{data['user']['screen_name']}]").rgb('0000FF') | |
end | |
sign.stringfile('1') do | |
color = colors.sort_by { rand }.first | |
print string("#{data['text']}").rgb color | |
end | |
}.write! | |
sleep 3 | |
end | |
}.join |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment