Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
How to Fill up a CouchDB with Twitter Statuses
require 'rubygems'
require 'json'
gem 'jchris-couchrest'
require 'couchrest'
require 'open3'
COUCHDB_HOST = "http://127.0.0.1:5984"
DB_NAME = 'tweet-spritzer'
SPRITZER_DB = CouchRest.database! "#{COUCHDB_HOST}/#{DB_NAME}"
SPRITZER_API_URL = 'http://stream.twitter.com/spritzer.json'
TWITTER_USERNAME = 'SET THIS'
TWITTER_PASSWORD = 'SET THIS'
SPRITZER_API_CMD ="curl #{SPRITZER_API_URL} -u#{TWITTER_USERNAME}:#{TWITTER_PASSWORD}"
def save_to_database doc
SPRITZER_DB.save_doc doc
STDOUT.print '.'
STDOUT.flush
end
Open3.popen3 SPRITZER_API_CMD do |stdin, stdout, stderr|
api_line = nil
begin
api_line = stdout.gets
save_to_database JSON.parse(api_line)
end until api_line.nil?
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment