Skip to content

Instantly share code, notes, and snippets.

@zdzolton
Created June 9, 2009 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zdzolton/126515 to your computer and use it in GitHub Desktop.
Save zdzolton/126515 to your computer and use it in GitHub Desktop.
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