aboutsummaryrefslogtreecommitdiff
path: root/pyaggr3g470r/views/feed.py
diff options
context:
space:
mode:
authorCédric Bonhomme <kimble.mandel+bitbucket@gmail.com>2015-03-04 07:48:14 +0100
committerCédric Bonhomme <kimble.mandel+bitbucket@gmail.com>2015-03-04 07:48:14 +0100
commit1c0ba8fad47489ce987e628605fd106f981d8075 (patch)
treeb381e4c8c910b2f2f282f6dadbda1a8c1938e358 /pyaggr3g470r/views/feed.py
parentTypo. (diff)
parentadding refresh rate to the profile form (diff)
downloadnewspipe-1c0ba8fad47489ce987e628605fd106f981d8075.tar.gz
newspipe-1c0ba8fad47489ce987e628605fd106f981d8075.tar.bz2
newspipe-1c0ba8fad47489ce987e628605fd106f981d8075.zip
Merged in jaesivsm/pyaggr3g470r/evol/api (pull request #6)
Evolution Arch, API and new crawler
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..2af502a7
--- /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.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.fromtimestamp(0)
+ first_article = 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