removed exception handler, implemented clean algorithm

This commit is contained in:
Ronald Schaten 2013-03-26 21:26:59 +01:00
parent 4f1bea7a6b
commit d0e2a69386

View File

@ -171,22 +171,22 @@ def process_feed_entry(session, feed, entry):
def fetch_single_feed(session, feed): def fetch_single_feed(session, feed):
print 'processing %s' % feed.url 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 fetched = False
# TODO: remove exception, see above if thisfeedinfo:
try: feed.feedinfo = thisfeedinfo
feed.feedinfo = query.one()
nextfetch = (feed.feedinfo.lastfetched + timedelta(minutes=feed.frequency)) nextfetch = (feed.feedinfo.lastfetched + timedelta(minutes=feed.frequency))
if datetime.now() > nextfetch: if datetime.now() > nextfetch:
print 'fetching...' print 'feed known, fetching...'
parser = feedparser.parse(feed.url) parser = feedparser.parse(feed.url)
fetched = True fetched = True
feed.feedinfo.update(parser) feed.feedinfo.update(parser)
else: else:
print 'not fetching before: %s' % nextfetch print 'not fetching before: %s' % nextfetch
except Exception, e: else:
print 'this feed seems to be new' print 'feed seems to be new, fetching...'
print 'fetching...'
parser = feedparser.parse(feed.url) parser = feedparser.parse(feed.url)
fetched = True fetched = True
feed.feedinfo = Feedinfo(parser) feed.feedinfo = Feedinfo(parser)