Created
June 9, 2009 13:59
-
-
Save zdzolton/126515 to your computer and use it in GitHub Desktop.
How to Fill up a CouchDB with Twitter Statuses
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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