diff options
author | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2015-03-15 23:59:14 +0100 |
---|---|---|
committer | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2015-03-15 23:59:14 +0100 |
commit | fb5df6041fc7bf97429bfe689e26fdc08e7e307f (patch) | |
tree | 6a9f6f39a2b0c8c7e3ca353ae6b624cfab5b312b /pyaggr3g470r/utils.py | |
parent | pylint check (diff) | |
download | newspipe-fb5df6041fc7bf97429bfe689e26fdc08e7e307f.tar.gz newspipe-fb5df6041fc7bf97429bfe689e26fdc08e7e307f.tar.bz2 newspipe-fb5df6041fc7bf97429bfe689e26fdc08e7e307f.zip |
A new test for the history page.
Diffstat (limited to 'pyaggr3g470r/utils.py')
-rwxr-xr-x | pyaggr3g470r/utils.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/pyaggr3g470r/utils.py b/pyaggr3g470r/utils.py index ba440c78..ae140327 100755 --- a/pyaggr3g470r/utils.py +++ b/pyaggr3g470r/utils.py @@ -54,6 +54,7 @@ from contextlib import contextmanager import conf from flask import g +from pyaggr3g470r import controllers from pyaggr3g470r.models import User, Feed, Article @@ -84,6 +85,31 @@ def fetch(id, feed_id=None): cmd = [conf.PYTHON, conf.basedir+'/manager.py', 'fetch_asyncio', str(id), str(feed_id)] p = subprocess.Popen(cmd, stdout=subprocess.PIPE) +def history(year=None, month=None): + """ + """ + import datetime, time, sqlalchemy + articles_counter = Counter() + if None != month and None != year: + articles = controllers.ArticleController(1).read(). \ + filter(sqlalchemy.extract('year', Article.date) == year). \ + filter(sqlalchemy.extract('month', Article.date) == month) + elif None != year: + articles = controllers.ArticleController(1).read(). \ + filter(sqlalchemy.extract('year', Article.date) == year) + else: + articles = controllers.ArticleController(1).read() + + for article in articles: + if None != month: + articles_counter[article.date.day] += 1 + elif None != year: + articles_counter[article.date.month] += 1 + else: + articles_counter[article.date.year] += 1 + + return articles_counter, articles + def import_opml(email, opml_content): """ Import new feeds from an OPML file. |