view backend/couchdb/FeedUpdater.py @ 144:74217db92993

updating feeds on the couchdb backend works now
author Dirk Olmes <dirk@xanthippe.ping.de>
date Wed, 24 Aug 2011 11:54:06 +0200
parents
children b290e29a94b5
line wrap: on
line source


from FeedEntry import FeedEntry
from backend.AbstractFeedUpdater import AbstractFeedUpdater
from datetime import datetime
import Feed
import logging

log = logging.getLogger("FeedUpdater")

class FeedUpdater(AbstractFeedUpdater):
    def __init__(self, feed, database):
        AbstractFeedUpdater.__init__(self, feed)
        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):
        log.info("new feed entry: " + entry.title)
        feedEntry = { "type" : "feedEntry", "feed" : self.feed._id, "link" : entry.link,
             "title" : entry.title, "summary" : entry.summary, "read" : False,
             "updated" : entry.updated}
        self.database.save(feedEntry)

    def _incrementFeedUpdateDate(self):
        updateDate = self.feed.incrementedUpdateDate()
        document = self.database.get(self.feed._id)
        document["next_update"] = datetime.strftime(updateDate, Feed.DATE_FORMAT)
        self.database.save(document)