aboutsummaryrefslogtreecommitdiff
path: root/pyaggr3g470r/views/feed.py
diff options
context:
space:
mode:
authorFrançois Schmidts <francois.schmidts@gmail.com>2015-01-17 16:50:38 +0100
committerFrançois Schmidts <francois.schmidts@gmail.com>2015-03-03 22:22:14 +0100
commit2849c82255b4b889c7342a0a8fa8a4aecfbe599d (patch)
tree3ad31fd3a0e84bc3f40367cf4963cf8db8c65d06 /pyaggr3g470r/views/feed.py
parentadding news fields and migrations scripts (diff)
downloadnewspipe-2849c82255b4b889c7342a0a8fa8a4aecfbe599d.tar.gz
newspipe-2849c82255b4b889c7342a0a8fa8a4aecfbe599d.tar.bz2
newspipe-2849c82255b4b889c7342a0a8fa8a4aecfbe599d.zip
a first big refacto of the existing arch
Diffstat (limited to 'pyaggr3g470r/views/feed.py')
-rw-r--r--pyaggr3g470r/views/feed.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/pyaggr3g470r/views/feed.py b/pyaggr3g470r/views/feed.py
new file mode 100644
index 00000000..fa9dc23d
--- /dev/null
+++ b/pyaggr3g470r/views/feed.py
@@ -0,0 +1,50 @@
+from datetime import datetime
+from flask import Blueprint, g, render_template
+
+from pyaggr3g470r import controllers, utils
+from pyaggr3g470r.decorators import pyagg_default_decorator, \
+ feed_access_required
+
+feeds_bp = Blueprint('feeds', __name__, url_prefix='/feeds')
+feed_bp = Blueprint('feed', __name__, url_prefix='/feed')
+
+@feeds_bp.route('/', methods=['GET'])
+def feeds():
+ "Lists the subscribed feeds in a table."
+ return render_template('feeds.html',
+ feeds=controllers.FeedController(g.user.id).read())
+
+
+@feed_bp.route('/<int:feed_id>', methods=['GET'])
+@pyagg_default_decorator
+@feed_access_required
+def feed(feed_id=None):
+ "Presents detailed information about a feed."
+ feed = controllers.FeedController(g.user.id).get(id=feed_id)
+ word_size = 6
+ articles = controllers.ArticleController(g.user.id)\
+ .read(feed_id=feed_id).all()
+ nb_articles = controllers.ArticleController(g.user.id).read().count()
+ top_words = utils.top_words(articles, n=50, size=int(word_size))
+ tag_cloud = utils.tag_cloud(top_words)
+
+ today = datetime.datetime.now()
+ try:
+ last_article = articles[0].date
+ first_article = articles[-1].date
+ delta = last_article - first_article
+ average = round(float(len(articles)) / abs(delta.days), 2)
+ except:
+ last_article = datetime.datetime.fromtimestamp(0)
+ first_article = datetime.datetime.fromtimestamp(0)
+ delta = last_article - first_article
+ average = 0
+ elapsed = today - last_article
+
+ return render_template('feed.html',
+ head_title=utils.clear_string(feed.title),
+ feed=feed, tag_cloud=tag_cloud,
+ first_post_date=first_article,
+ end_post_date=last_article,
+ nb_articles=nb_articles,
+ average=average, delta=delta, elapsed=elapsed)
bgstack15