Hi, I want to use the TweetStream gem
http://github.com/intridea/tweetstreamin my Rails app
I can’t seem to figure out how to do it, because it opens a connection
and
then won’t move on.
I got it to work in a Ruby script with
---------- start code ----------
require ‘rubygems’
require ‘tweetstream’
user = ‘blinkdev’
password = secret
keyword = ‘#ROCKPIC’
Thread.new do
TweetStream::Client.new(user,password).track(keyword) do |status|
puts “[#{status.created_at}-#{status.user.screen_name}]
#{status.text}”
end
end
loop do
sleep 10
puts “other stuff happening”
end
---------- end code ----------
Which gives the output:
other stuff happening
other stuff happening
[Mon Mar 01 20:30:59 +0000 2010-blinkdev] test #ROCKPIC 7
other stuff happening
So I tried to replicate that in my Rails app in the file
config/initializers/twitter_stream.rb
---------- start code ----------
require ‘rubygems’
require ‘tweetstream’
Thread.new do
logger.info “started tweetstream”
TweetStream::Client.new(‘blinkdev’,secret).track(‘#ROCKPIC’) do
|status|
message = “[#{status.created_at}-#{status.user.screen_name}]
#{status.text}”
logger.info message
logger.info Rockpic.new( :message => message ).save!
end
end
---------- end code ----------
But it didn’t work. I couldn’t get it to log anything either. So I went
and
tried it in the console:
---------- start code ----------
$script/console
Loading development environment (Rails 2.3.3)
require ‘rubygems’
=> []
require ‘tweetstream’
=> []
?> Thread.new do
?> logger.info “started tweetstream”
?> TweetStream::Client.new(‘blinkdev’,secret).track(‘#ROCKPIC’) do
|status|
?> message = “[#{status.created_at}-#{status.user.screen_name}]
#{status.text}”
logger.info message logger.info Rockpic.new( :message => message ).save!
end
?> end
=> #<Thread:0x24ba60c dead>
---------- end code ----------
It doesn’t seem to do anything. I tried playing with daemons, but I
can’t
figure out how to use them either.
If someone can show me how to use daemons, I’ll give that a try (I have
the
daemons gem installed daemons | RubyGems.org | your community gem host) and it looks
like
TweetStream has their own version with Daemons,
http://rdoc.info/rdoc/intridea/tweetstream/blob/e5ecb9ef125ebce038d24f816973bbb4644445a8/TweetStream/Daemon.htmlbut
I can’t seem to get it to do anything:
---------- start code ----------
ARGV << ‘start’
require ‘rubygems’
require ‘tweetstream’
user = ‘blinkdev’
password = secret
keyword = ‘#ROCKPIC’
TweetStream::Daemon.new(user,password, ‘tracker’).track(keyword) do
|status|
puts “[#{status.created_at}-#{status.user.screen_name}]
#{status.text}”
end
---------- end code ----------
It runs, but it doesn’t respond to anything, and I think I need it to
run in
the Rails environment, because I want to host it on Heroku. Anyway, I’m
not
sure where to go with it, I just want my Rails app to have a stream to
twitter to watch for a given hash tag, and a particular user’s tweets.
Any help would be appreciated.