#!/usr/bin/python # Created by Matteo Rattotti on 13/03/06. # Copyright (c) 2006 - 2007 Shiny Frog. All rights reserved. # Contact matteo.rattotti@shinyfrog.net 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. import deliStore import getDelApi import pickle import os versionFile = "delibarData-0.9.pk" class deliLoader: def __init__(self): self.pathFile = os.path.expanduser("~/") + "Library/Application Support/Delibar/" if not os.path.exists(self.pathFile): os.mkdir(self.pathFile) def getLocal(self): """ Get data file locally, if they exist, return a deliStore obj """ try: file = open(self.pathFile + versionFile, 'r') dataFile = pickle.load(file) file.close() except: 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-[VERSION].pk """ deliData = getDelApi.dataGrabber(user, pwd, proxy).returnData() store = deliStore.deliStore(deliData['tags'], deliData['posts'], deliData['bundles'], deliData['recent']) file = open(self.pathFile + versionFile, 'w') pickle.dump(deliData, file) file.close() return store if __name__ == "__main__": d = deliLoader() c = d.getLocal() c.sortTagByFreq() print c.tags #c = d.getNet('delibarTest', 'delibarTest') #for tag in c.google: # print tag