aboutsummaryrefslogtreecommitdiff
path: root/src/web
diff options
context:
space:
mode:
authorCédric Bonhomme <cedric@cedricbonhomme.org>2016-09-20 18:05:33 +0200
committerCédric Bonhomme <cedric@cedricbonhomme.org>2016-09-20 18:05:33 +0200
commit0b82405c091aad39ade4a57978e7997b7f9d5dd3 (patch)
treec34920bd6eab63e0779777d7e4e54223dff5cf46 /src/web
parentsimple test of a 'popular' page. (diff)
downloadnewspipe-0b82405c091aad39ade4a57978e7997b7f9d5dd3.tar.gz
newspipe-0b82405c091aad39ade4a57978e7997b7f9d5dd3.tar.bz2
newspipe-0b82405c091aad39ade4a57978e7997b7f9d5dd3.zip
Improved the way we count feeds by link.
Diffstat (limited to 'src/web')
-rw-r--r--src/web/controllers/feed.py3
-rw-r--r--src/web/views/views.py12
2 files changed, 8 insertions, 7 deletions
diff --git a/src/web/controllers/feed.py b/src/web/controllers/feed.py
index a3f5cae7..c67c6bea 100644
--- a/src/web/controllers/feed.py
+++ b/src/web/controllers/feed.py
@@ -70,6 +70,9 @@ class FeedController(AbstractController):
def count_by_category(self, **filters):
return self._count_by(Feed.category_id, filters)
+ def count_by_link(self, **filters):
+ return self._count_by(Feed.link, filters)
+
def _ensure_icon(self, attrs):
if not attrs.get('icon_url'):
return
diff --git a/src/web/views/views.py b/src/web/views/views.py
index c3425a17..ceb1ab10 100644
--- a/src/web/views/views.py
+++ b/src/web/views/views.py
@@ -1,5 +1,5 @@
import logging
-from collections import Counter
+import operator
from flask import (request, render_template, flash,
url_for, redirect, current_app)
from flask_babel import gettext
@@ -45,12 +45,10 @@ def handle_sqlalchemy_assertion_error(error):
@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))
+ feeds = FeedController().count_by_link()
+ sorted_feeds = sorted(feeds.items(), key=operator.itemgetter(1),
+ reverse=True)
+ return render_template('popular.html', popular=sorted_feeds)
@current_app.route('/about', methods=['GET'])
bgstack15