From 691cb7048e233c76f5571a04f5c8fd12b57736d6 Mon Sep 17 00:00:00 2001 From: cedricbonhomme Date: Mon, 6 Jun 2011 22:38:47 +0200 Subject: Bugfix: IndexError: list index out of range when a feed is empty. --- pyAggr3g470r.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/pyAggr3g470r.py b/pyAggr3g470r.py index 9ce4bc80..737b109e 100755 --- a/pyAggr3g470r.py +++ b/pyAggr3g470r.py @@ -556,23 +556,25 @@ class Root: html += "

The feed " + feed.feed_title + " contains " + str(feed.nb_articles) + " articles. " html += "Representing " + str((round(float(feed.nb_articles) / self.nb_articles, 4)) * 100) + " % of the total " html += "(" + str(self.nb_articles) + ").

" - html += "

" + (feed.nb_unread_articles == 0 and ["All articles are read"] or [str(feed.nb_unread_articles) + \ - " unread article" + (feed.nb_unread_articles == 1 and [""] or ["s"])[0]])[0] + ".

" + if feed.articles.values() != []: + html += "

" + (feed.nb_unread_articles == 0 and ["All articles are read"] or [str(feed.nb_unread_articles) + \ + " unread article" + (feed.nb_unread_articles == 1 and [""] or ["s"])[0]])[0] + ".

" if feed.mail == "1": html += """

You are receiving articles from this feed to the address: %s. """ % \ (utils.mail_to, utils.mail_to) html += """Stop receiving articles from this feed.

""" % \ (feed.feed_id, ) - last_article = utils.string_to_datetime(feed.articles.values()[0].article_date) - first_article = utils.string_to_datetime(feed.articles.values()[-1].article_date) - delta = last_article - first_article - delta_today = datetime.datetime.fromordinal(datetime.date.today().toordinal()) - last_article - html += "

The last article was posted " + str(abs(delta_today.days)) + " day(s) ago.

" - if delta.days > 0: - html += """

Daily average: %s,""" % (str(round(float(feed.nb_articles)/abs(delta.days), 2)),) - html += """ between the %s and the %s.

\n""" % \ - (feed.articles.values()[-1].article_date[:10], feed.articles.values()[0].article_date[:10]) + if feed.articles.values() != []: + last_article = utils.string_to_datetime(feed.articles.values()[0].article_date) + first_article = utils.string_to_datetime(feed.articles.values()[-1].article_date) + delta = last_article - first_article + delta_today = datetime.datetime.fromordinal(datetime.date.today().toordinal()) - last_article + html += "

The last article was posted " + str(abs(delta_today.days)) + " day(s) ago.

" + if delta.days > 0: + html += """

Daily average: %s,""" % (str(round(float(feed.nb_articles)/abs(delta.days), 2)),) + html += """ between the %s and the %s.

\n""" % \ + (feed.articles.values()[-1].article_date[:10], feed.articles.values()[0].article_date[:10]) html += "

Recent articles

" for article in feed.articles.values()[:10]: -- cgit