Created
January 6, 2010 11:59
-
-
Save neilfws/270228 to your computer and use it in GitHub Desktop.
Archive a FriendFeed feed in MongoDB
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
namespace :db do | |
require "mongo" | |
require "json/pure" | |
require "open-uri" | |
feed = ENV['feed'] | |
db = Mongo::Connection.new.db('friendfeed') | |
col = db.collection('entries') | |
desc "Seed database with feed entries" | |
task :seed do | |
0.step(9900, 100) do |n| | |
j = JSON.parse(open("http://friendfeed-api.com/v2/feed/#{feed}?start=#{n}&num=100").read) | |
break if j['entries'].count == 0 | |
entries = j['entries'] | |
j.delete('entries') | |
j['updated_at'] = Time.now | |
entries.each do |entry| | |
entry['_id'] = "#{j['sup_id']}/#{entry['id']}" | |
entry.delete('id') | |
entry['feed'] = j | |
col.save(entry) | |
end | |
puts "Processed entries #{n} - #{n + 99}" | |
sleep(3) | |
end | |
puts "Done: database contains #{col.count} entries." | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Added a sleep() to this version of code.