0

I need to stream tweets and store it in mongodb for processing. I have installed ruby and the mongo and tweetstream gems.

I run the below code to extract tweets and store it in a collection named "users" in "tweet" database of mongodb. Here is the program rawks.rb

require "tweetstream"
require "mongo"
require "time"
db = Mongo::Connection.new("localhost", 27017).db("tweet")
tweets = db.collection("users")
TweetStream::Daemon.new("username","password","scrapedaemon").on_error do |message|
# Log your error message somewhere
end.filter({"locations" => "-12.72216796875, 49.76707407366789, 1.977539, 61.068917"}) do    |status|
# Do things when nothing's wrong
data = {"created_at" => Time.parse(status.created_at), "text" => status.text, "geo" =>      status.geo, "coordinates" => status.coordinates, "id" => status.id, "id_str" => status.id_str}
tweets.insert({"data" => data});
end

When i run this file, i get the following error : from rawks.rb:8:in 'new' rawks.rb:8:in ''

In file daemon.rb, 40:in 'initialize' wrong number of arguments (3 for 2) Argument error

Here is the daemon.rb file

require 'daemons'

# A daemonized TweetStream client that will allow you to
# create backgroundable scripts for application specific
# processes. For instance, if you create a script called
# <tt>tracker.rb</tt> and fill it with this:
#
#     require 'rubygems'
#     require 'tweetstream'
#
#     TweetStream.configure do |config|
#       config.consumer_key = 'abcdefghijklmnopqrstuvwxyz'
#       config.consumer_secret = '0123456789'
#       config.oauth_token = 'abcdefghijklmnopqrstuvwxyz'
#       config.oauth_token_secret = '0123456789'
#       config.auth_method = :oauth
#     end
#
#     TweetStream::Daemon.new('tracker').track('intridea') do |status|
#       # do something here
#     end
#
# And then you call this from the shell:
#
#     ruby tracker.rb start
#
# A daemon process will spawn that will automatically
# run the code in the passed block whenever a new tweet
# matching your search term ('intridea' in this case)
# is posted.
#
class TweetStream::Daemon < TweetStream::Client
DEFAULT_NAME = 'tweetstream'.freeze
DEFAULT_OPTIONS = {:multiple => true}

attr_accessor :app_name, :daemon_options

# The daemon has an optional process name for use when querying
# running processes.  You can also pass daemon options.
def initialize(name = DEFAULT_NAME, options = DEFAULT_OPTIONS)
@app_name = name
@daemon_options = options
super({})
end

def start(path, query_parameters = {}, &block) #:nodoc:
Daemons.run_proc(@app_name, @daemon_options) do
super(path, query_parameters, &block)
end
end
end

1 Answers1

0

You do

TweetStream::Daemon.new("username","password","scrapedaemon")

which has three params, but should have only two, the second being a hash of options:

initialize(name = DEFAULT_NAME, options = DEFAULT_OPTIONS)

(there seem to be different docs for that, the one at ruby-doc.org showing the usage as you tried, but the source you use looks more like described here: http://rdoc.info/github/intridea/tweetstream/TweetStream/Daemon)

thorsten müller
  • 5,621
  • 1
  • 22
  • 30