Esempio n. 1
0
class HubbubItem(Persist):

    """ item that contains hubbub data """


    def __init__(self, name, url="", owner="", itemslist=['title', 'link'], watchchannels=[], running=1):
        filebase = getdatadir() + os.sep + 'plugs' + os.sep + 'jsb.plugs.wave.hubbub' + os.sep + name
        Persist.__init__(self, filebase + os.sep + name + '.core')
        if not self.data: self.data = {}
        self.data = LazyDict(self.data)
        self.data['name'] = self.data.name or str(name)
        self.data['url'] = self.data.url or str(url)
        self.data['owner'] = self.data.owner or str(owner)
        self.data['watchchannels'] = self.data.watchchannels or list(watchchannels)
        self.data['running'] = self.data.running or running
        self.itemslists = Pdol(filebase + os.sep + name + '.itemslists')
        self.markup = Pdod(filebase + os.sep + name + '.markup')

    def save(self):
        """ save the hubbub items data. """
        Persist.save(self)
        self.itemslists.save()
        self.markup.save()

    def ownercheck(self, userhost):
        """ check is userhost is the owner of the feed. """
        try: return self.data.owner == userhost
        except KeyError: pass
        return False

    def fetchdata(self):
        """ get data of rss feed. """
        url = self.data['url']
        if not url:
            logging.warn("hubbub - %s doesnt have url set" % self.data.name)
            return []
        result = feedparser.parse(url, agent=useragent())
        logging.debug("hubbub - fetch - got result from %s" % url)
        if result and result.has_key('bozo_exception'): logging.info('hubbub - %s bozo_exception: %s' % (url, result['bozo_exception']))
        try:
            status = result.status
            logging.info("hubbub - status is %s" % status)
        except AttributeError: status = 200
        if status != 200 and status != 301 and status != 302: raise RssStatus(status)
        return result.entries