view backend/couchdb/FeedUpdater.py @ 165:a5bda54309ba

add a couchapp for easy/automated setup
author Dirk Olmes <dirk@xanthippe.ping.de>
date Mon, 29 Aug 2011 04:12:01 +0200
parents 2940e74c9663
children 04c3b9796b89
line wrap: on
line source


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

log = logging.getLogger("FeedUpdater")

class FeedUpdater(AbstractFeedUpdater):
    @staticmethod
    def createFeed(url, database):
        feedDict = feedparser.parse(url)
        if feedDict.has_key("title"):
            title = feedDict["feed"].title
        else:
            title = url
        feed = Feed.create(url, title)
        feed.store(database)
        FeedUpdater(feed, database).update(feedDict)

    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 = 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)