Skip to content

Instantly share code, notes, and snippets.

@jandot
Created August 11, 2009 09:10
Show Gist options
  • Save jandot/165714 to your computer and use it in GitHub Desktop.
Save jandot/165714 to your computer and use it in GitHub Desktop.
require 'open-uri'
require 'json'
require 'mongo'
class FriendFeed
attr_accessor :user, :database, :collection
def initialize(user, database, collection)
@user = user
@database = XGen::Mongo::Driver::Mongo.new.db(database)
@collection = @database.collection(collection)
end
def get_url(start, num)
return "http://friendfeed-api.com/v2/feed/#{@user}?start=#{start.to_s}&num=#{num.to_s}"
end
def read(start = 1, num = 100)
return JSON.parse(open(get_url(start, num)).read)
end
def backup(start,num)
items = self.read(start, num)
# TODO: check if posts are already in db or not. Something like
# @collection.find_first['entries'].select{|e| e[id] = "e/25654af6847df198f71195d7f7c0b73f"}
@collection.save(items)
end
end
if __FILE__ == $0
ff = FriendFeed.new('jandot', 'friendfeed', 'items')
ff.backup(1,20)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment