view backend/couchdb/FeedUpdater.py @ 211:1ac0b8e2feae

wrap the individual feed update with an exception handler so that a sinlge broken feed doesn't halt the entire update process
author Dirk Olmes <dirk@xanthippe.ping.de>
date Mon, 12 Nov 2012 08:10:40 +0100
parents 95445513cc34
children bb3c851b18b1
line wrap: on
line source


from FeedEntry import FeedEntry
from backend.AbstractFeedUpdater import AbstractFeedUpdater
import logging

log = logging.getLogger("FeedUpdater")

class FeedUpdater(AbstractFeedUpdater):
    def __init__(self, database, preferences):
        AbstractFeedUpdater.__init__(self, preferences)
        self.database = database

    def _processEntry(self, entry):
        feedEntry = FeedEntry.findByLink(entry.link, self.database)
        if feedEntry is None:
            self._createFeedEntry(entry)

    def _createFeedEntry(self, entry):
        if hasattr(entry, "published"):
            log.info("new feed entry: %s (%s)" % (entry.title, entry.published))
        else:
            log.info("new feed entry: %s" % (entry.title))
        feedEntry = FeedEntry()
        feedEntry.feed = self.feed.id
        feedEntry.link = entry.link
        feedEntry.title = entry.title
        feedEntry.summary = entry.summary
        feedEntry.updated = entry.updated_parsed
        feedEntry.store(self.database)

    def _incrementFeedUpdateDate(self):
        self.feed.incrementNextUpdateDate()
        self.feed.store(self.database)

    def _setFeedTitle(self, feedDict):
        oldTitle = self.feed.title
        AbstractFeedUpdater._setFeedTitle(self, feedDict)
        if oldTitle != self.feed.title:
            self.feed.store(self.database)