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