diff options
author | cedricbonhomme <devnull@localhost> | 2011-06-06 22:14:29 +0200 |
---|---|---|
committer | cedricbonhomme <devnull@localhost> | 2011-06-06 22:14:29 +0200 |
commit | e9ac46e16e7c6bffeca8652193203493bb641c58 (patch) | |
tree | e85e75fec7cf0e1534655054d6b5ac803df5a889 | |
parent | Improvement. Daily post average. (diff) | |
download | newspipe-e9ac46e16e7c6bffeca8652193203493bb641c58.tar.gz newspipe-e9ac46e16e7c6bffeca8652193203493bb641c58.tar.bz2 newspipe-e9ac46e16e7c6bffeca8652193203493bb641c58.zip |
Bugfix: ZeroDivisionError when calculating the 'Daily post average' value if there is only one article in the feed.
-rwxr-xr-x | pyAggr3g470r.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/pyAggr3g470r.py b/pyAggr3g470r.py index 824b6d2d..9ce4bc80 100755 --- a/pyAggr3g470r.py +++ b/pyAggr3g470r.py @@ -569,9 +569,10 @@ class Root: delta = last_article - first_article delta_today = datetime.datetime.fromordinal(datetime.date.today().toordinal()) - last_article html += "<p>The last article was posted " + str(abs(delta_today.days)) + " day(s) ago.</p>" - html += """<p>Daily average: %s,""" % (str(round(float(feed.nb_articles)/abs(delta.days), 2)),) - html += """ between the %s and the %s.</p>\n""" % \ - (feed.articles.values()[-1].article_date[:10], feed.articles.values()[0].article_date[:10]) + if delta.days > 0: + html += """<p>Daily average: %s,""" % (str(round(float(feed.nb_articles)/abs(delta.days), 2)),) + html += """ between the %s and the %s.</p>\n""" % \ + (feed.articles.values()[-1].article_date[:10], feed.articles.values()[0].article_date[:10]) html += "<br /><h1>Recent articles</h1>" for article in feed.articles.values()[:10]: |