Мне нужно передать твиты и сохранить их в mongodb для обработки. Я установил рубин и драгоценные камни mongo и tweetstream.извлечение твитов с использованием ruby
Я запускаю приведенный ниже код, чтобы извлечь твиты и сохранить его в коллекции с именем «пользователи» в базе данных «tweet» mongodb. Вот программа 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
Когда я запустить этот файл, я получаю следующее сообщение об ошибке: из rawks.rb: 8: в 'новой' rawks.rb: 8: в ''
в файле daemon.rb, 40: в 'инициализации' неверное число аргументов (3 для 2) ошибки
Здесь аргумент файл daemon.rb
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 = ''
# config.oauth_token = 'abcdefghijklmnopqrstuvwxyz'
# config.oauth_token_secret = ''
# 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