Permalink
Browse files

dumped tweetstream, using EM-friendly twitter-stream now (thx @method…

  • Loading branch information...
rubenfonseca committed Dec 27, 2009
1 parent c3da091 commit c6babfb268a398428f6ecf9023d429f65534b015
Showing with 12 additions and 18 deletions.
  1. +1 −2 Gemfile
  2. +1 −1 client/index.html
  3. +1 −2 socket.rb
  4. +9 −13 twitterfeed.rb
View
@@ -1,5 +1,4 @@
gem "amqp"
gem "eventmachine"
gem "em-websocket"
-gem "tweetstream"
-gem "json"
+gem "twitter-stream"
View
@@ -13,7 +13,7 @@
ws = new WebSocket("ws://localhost:8080/");
ws.onmessage = function(evt) {
data = eval("(" + evt.data + ")");
- var p = $("<div class='tweet' style='display:none'><div class='content'><a class='main-screenname' href='http://www.twitter.com/" + data.username + "/status/" + data.id + "' target='_blank'>" + data.username + "</a> " + data.text + "</div></div>");
+ var p = $("<div class='tweet' style='display:none'><div class='content'><a class='main-screenname' href='http://www.twitter.com/" + data.user.screen_name + "/status/" + data.id + "' target='_blank'>" + data.user.screen_name + "</a> " + data.text + "</div></div>");
if($('#tweets div.tweet').size() > 15) {
$('#tweets div.tweet:last').slideDown(100, function() {
$(this).remove();
View
@@ -1,15 +1,14 @@
require 'vendor/gems/environment'
require 'em-websocket'
require 'mq'
-require 'json'
EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 8080) do |ws|
ws.onopen do
puts "WebSocket opened"
twitter = MQ.new
twitter.queue('twitter').bind(twitter.fanout('twitter')).subscribe do |t|
- ws.send Marshal.load(t).to_json
+ ws.send t
end
end
View
@@ -1,24 +1,20 @@
require 'vendor/gems/environment'
require 'mq'
-require 'tweetstream'
+require 'twitter/json_stream'
username = ARGV.shift
password = ARGV.shift
raise "need username and password" if !username or !password
AMQP.start(:host => 'localhost') do
twitter = MQ.new.fanout('twitter')
-
- Thread.new do
- TweetStream::Client.new(username, password).track('iphone') do |status|
- t = {
- :id => status[:id],
- :username => status.user.screen_name,
- :text => status.text,
- :profile_image_url => status.user.profile_image_url
- }
- puts status.text
- twitter.publish(Marshal.dump(t))
- end
+
+ stream = Twitter::JSONStream.connect(
+ :path => '/1/statuses/filter.json?track=iphone',
+ :auth => "#{username}:#{password}"
+ )
+
+ stream.each_item do |status|
+ twitter.publish(status)
end
end

0 comments on commit c6babfb

Please sign in to comment.