Skip to content

Instantly share code, notes, and snippets.

@timbuchwaldt
Forked from samsm/file.rb
Created December 28, 2009 12:51
Show Gist options
  • Save timbuchwaldt/264655 to your computer and use it in GitHub Desktop.
Save timbuchwaldt/264655 to your computer and use it in GitHub Desktop.
Loads the latest 1500 Tweets containing couchdb and saves them to the db
# 1. Install CouchDBX. Fire it up. (OS X only.)
# 2. sudo gem install couchrest json
# 3. Think up a nice keyword.
# 4. irb
require 'couchrest'
require 'open-uri'
require 'json'
database_name = 'twitter-test'
@db = CouchRest.database!("http://127.0.0.1:5984/#{database_name}")
twitter_search_url = "http://search.twitter.com/search.json?"
keyword = 'couchdb'
results = Array.new
(1..15).each do |n|
JSON.parse(open("#{twitter_search_url}q=#{keyword}&rpp=100&page=#{n}").read)['results'].each do |post|
results << post
end
@db.bulk_save(results)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment