From 2abfc7c43131e0366137b27b0b75132da6ef6582 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Tue, 20 Sep 2016 15:31:12 +0200 Subject: simple test of a 'popular' page. --- src/web/templates/popular.html | 13 +++++++++++++ src/web/views/views.py | 13 +++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/web/templates/popular.html diff --git a/src/web/templates/popular.html b/src/web/templates/popular.html new file mode 100644 index 00000000..6b2e9001 --- /dev/null +++ b/src/web/templates/popular.html @@ -0,0 +1,13 @@ +{% extends "layout.html" %} +{% block content %} +
+

Popular feeds

+ +
+{% endblock %} diff --git a/src/web/views/views.py b/src/web/views/views.py index a7c842d7..c3425a17 100644 --- a/src/web/views/views.py +++ b/src/web/views/views.py @@ -1,9 +1,11 @@ import logging +from collections import Counter from flask import (request, render_template, flash, url_for, redirect, current_app) from flask_babel import gettext from conf import API_ROOT +from web.controllers import FeedController from web.lib.view_utils import etag_match logger = logging.getLogger(__name__) @@ -40,6 +42,17 @@ def handle_sqlalchemy_assertion_error(error): return error.args[0], 400 +@current_app.route('/popular', methods=['GET']) +@etag_match +def popular(): + feeds = FeedController().read().all() + counter = Counter() + for feed in feeds: + counter[feed.link] += 1 + print(counter.most_common(50)) + return render_template('popular.html', popular=counter.most_common(50)) + + @current_app.route('/about', methods=['GET']) @etag_match def about(): -- cgit