From d0e2a69386efd7ae2ccffc009cf2aea11ad0c809 Mon Sep 17 00:00:00 2001 From: Ronald Schaten Date: Tue, 26 Mar 2013 21:26:59 +0100 Subject: [PATCH] removed exception handler, implemented clean algorithm --- atomstrom.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/atomstrom.py b/atomstrom.py index 1fe6109..c40ccd5 100755 --- a/atomstrom.py +++ b/atomstrom.py @@ -171,22 +171,22 @@ def process_feed_entry(session, feed, entry): def fetch_single_feed(session, feed): print 'processing %s' % feed.url - query = session.query(Feedinfo).filter(Feedinfo.feed_id==feed.id) + thisfeedinfo = session.query(Feedinfo).\ + filter(Feedinfo.feed_id==feed.id).\ + first() fetched = False - # TODO: remove exception, see above - try: - feed.feedinfo = query.one() + if thisfeedinfo: + feed.feedinfo = thisfeedinfo nextfetch = (feed.feedinfo.lastfetched + timedelta(minutes=feed.frequency)) if datetime.now() > nextfetch: - print 'fetching...' + print 'feed known, fetching...' parser = feedparser.parse(feed.url) fetched = True feed.feedinfo.update(parser) else: print 'not fetching before: %s' % nextfetch - except Exception, e: - print 'this feed seems to be new' - print 'fetching...' + else: + print 'feed seems to be new, fetching...' parser = feedparser.parse(feed.url) fetched = True feed.feedinfo = Feedinfo(parser)