1

I am trying to get the tweets using twitterstream gem.

list_of_users = [612473, 759251, 1367531, 6017542, 6509832]
TweetStream::Client.new.follow(list_of_users) do |status|
  puts "follow [#{status.user.id}]\t[#{status.user.screen_name}]\t#{status.text}"
end

Now I am able to fetch the tweets from those users in list. But if I add another user to my database How can I ask TwitterStream to follow that new user?

I need my program to check my database for new user in a particular interval and if my DB contains new user then it should start fetching the tweets from that new user.

Thank you

Community
  • 1
  • 1
RSK
  • 17,210
  • 13
  • 54
  • 74
  • What are you using to access your database? ActiveRecord? – Andrew Grimm Mar 26 '12 at 22:19
  • @AndrewGrimm : yes using ActiveRecord. But my issue is not with fetching users from DB. `TweetStream::Client.new.follow(list_of_users)` uses EventMachine and when I call `follow` it enters into a Infinite loop. SO I think I need to stop it from some point, update the users list and again call follow with new list of users. – RSK Mar 27 '12 at 06:28

1 Answers1

0

One way to do that is simply adding an after create callback in your user model.

Model User 
  after_create :get_tweets

  def get_tweets
    # your TweetStream code
  end
end

Another way would be to have a boolean on your user model: is_followed and simply find all the users where(is_followed: false ).

If you want the task to run regularly, use something like resque. Perfect for that kind of regular tasks.

Alexis Perrier
  • 683
  • 9
  • 13