#!/usr/bin/python # Created by Matteo Rattotti on 13/03/06. # Copyright (c) 2006 Matteo Rattotti. All rights reserved. # Contact matteo.rattotti@gmail.com for any problem # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ''' Delegate interface for opening del.icio.us data by local or by net ''' __version__ = "0.1" __author__ = "Matteo Rattotti" __contact__ = "http://www.rknet.it" __date__ = 'Fri Dec 16 15:22:18 2005' __timestamp__ = '1134742938' import deliStore import getDelApi import pickle import os class loader: """ Loader is the class that load whole del.icio.us information in a deliStore object, either by net or by local. Get info by net will eventually write it on disk. """ def __init__(self): self.pathFile = os.path.expanduser("~/") + "Library/Application Support/Delibar/" def getLocal(self): """ Get data file locally, if they exist, return a deliStore obj """ try: file = open(self.pathFile + "data.delibar0.8", 'r') dataFile = pickle.load(file) file.close() except: print "Data file not found! Try get online and do a reload!" raise store = deliStore.deliStore(dataFile['tags'], dataFile['posts'], dataFile['bundles'], dataFile['recent']) return store def getNet(self, user, pwd, proxy=None): """ Get file by Net, return a deliStore obj. Also write file on disk, in ~/Library/Application Support/Delibar/data.delibar """ deliData = getDelApi.dataGrabber(user, pwd, proxy).returnData() store = deliStore.deliStore(deliData['tags'], deliData['posts'], deliData['bundles'], deliData['recent']) if not os.path.exists(self.pathFile): os.mkdir(self.pathFile) else: file = open(self.pathFile + "data.delibar0.8", 'w') pickle.dump(deliData, file) file.close return store if __name__ == '__main__': l = loader() data = l.getNet('blackfede', 'blackfede') #data = l.getLocal() tag = "ovolollo" for u in data.__getattr__(tag): print u