view backend/sqlalchemy/FeedUpdater.py @ 249:5695197a3ca5

Add an about Qt help menu item
author Dirk Olmes <dirk@xanthippe.ping.de>
date Thu, 09 Jun 2016 05:19:03 +0200
parents bb3c851b18b1
children
line wrap: on
line source

# -*- coding: utf-8 -*-
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 _findFeedsToUpdate(session):
    return session.query(Feed).filter(Feed.next_update < datetime.now())

class FeedUpdater(AbstractFeedUpdater):
    @staticmethod
    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 __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()