#!/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. ''' data structure for delicious post, pythonic way! ''' __version__ = "0.1" __author__ = "Matteo Rattotti" __contact__ = "http://www.rknet.it" __date__ = 'Wed Dec 7 16:07:36 2005' __timestamp__ = '1133968056' import getDelApi class deliStore(object): "Class store for post-like object" def __init__(self, tag, posts, bundles, recent): "Initialize the tag and post" self.tag = tag self.posts = posts self.deliBundles = bundles self.deliRecent = recent def returnBundles(self): return self.deliBundles def returnRecent(self): return self.deliRecent def __getattr__(self, name): """ Rewritten __getattr__ for having freebeer like for item in yourdelicious.yourtag: print item['url'] """ if name in self.tag: tmpList = [] for post in self.posts: if name in post['tag'].split(" "): tmpList.append(post) return tmpList elif name in self.__dict__: return self.__dict__[name] else: return [] if __name__ == '__main__': deliData = getDelApi.dataGrabber('ksinkc', 'laksjdhfg').returnData() print deliData data = deliStore(deliData['tags'], deliData['posts'], [], []) for a in data.tag: try: print a print type(a) except: pass