Created
August 11, 2009 09:10
-
-
Save jandot/165714 to your computer and use it in GitHub Desktop.
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 '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