Mercurial > hg > Feedworm
view backend/sqlalchemy/FeedUpdater.py @ 167:a3c945ce434c
adjust the sqlalchemy backend to the changes in AbstractFeedUpdater
author | dirk |
---|---|
date | Mon, 05 Sep 2011 19:39:08 +0200 |
parents | 86f828096aaf |
children | f4708d38419c |
line wrap: on
line source
from Feed import Feed from FeedEntry import FeedEntry from backend.AbstractFeedUpdater import AbstractFeedUpdater, FeedUpdateException from datetime import datetime import logging log = logging.getLogger("FeedUpdater") def updateAllFeeds(preferences, session): allFeeds = findFeedsToUpdate(session) for feed in allFeeds: try: FeedUpdater(preferences, session).update(feed) except FeedUpdateException, fue: log.warn("problems while updating feed " + feed.rss_url + ": " + str(fue)) session.commit() def findFeedsToUpdate(session): return session.query(Feed).filter(Feed.next_update < datetime.now()) class FeedUpdater(AbstractFeedUpdater): def __init__(self, preferences, session): AbstractFeedUpdater.__init__(self, preferences) self.session = session def _processEntry(self, entry): feedEntry = FeedEntry.findById(entry.id, self.session) if feedEntry is None: self._createFeedEntry(entry) def _createFeedEntry(self, entry): new = FeedEntry.create(entry) new.feed = self.feed self.session.add(new) log.info("new feed entry: " + entry.title) def _incrementFeedUpdateDate(self): self.feed.incrementNextUpdateDate()