From db93e5d9f624ad565c578985414f4bc9fd452ac2 Mon Sep 17 00:00:00 2001 From: lza_menace Date: Wed, 16 Sep 2020 11:32:16 -0700 Subject: [PATCH] setting up poster leaderboard --- suchwow/app.py | 3 ++- suchwow/routes/leaderboard.py | 28 ++++++++++++++++++++++++++++ suchwow/templates/index.html | 6 ++++-- suchwow/templates/leaderboard.html | 23 +++++++++++++++++++++++ suchwow/templates/navbar.html | 3 +++ 5 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 suchwow/routes/leaderboard.py create mode 100644 suchwow/templates/leaderboard.html diff --git a/suchwow/app.py b/suchwow/app.py index 92ec23e..90e8398 100644 --- a/suchwow/app.py +++ b/suchwow/app.py @@ -5,7 +5,7 @@ from flask import render_template, flash from flask_session import Session from suchwow import config from suchwow.models import Post, Profile, Comment, Notification, db -from suchwow.routes import auth, comment, post, profile +from suchwow.routes import auth, comment, post, profile, leaderboard from suchwow.utils.decorators import login_required from suchwow import wownero @@ -19,6 +19,7 @@ app.register_blueprint(post.bp) app.register_blueprint(auth.bp) app.register_blueprint(profile.bp) app.register_blueprint(comment.bp) +app.register_blueprint(leaderboard.bp) @app.route("/") def index(): diff --git a/suchwow/routes/leaderboard.py b/suchwow/routes/leaderboard.py new file mode 100644 index 0000000..e3ff737 --- /dev/null +++ b/suchwow/routes/leaderboard.py @@ -0,0 +1,28 @@ +from os import path +from flask import render_template, Blueprint, request, session, flash +from flask import send_from_directory, redirect, url_for, current_app +from werkzeug.utils import secure_filename +from suchwow import wownero +from suchwow.models import Post + + +bp = Blueprint("leaderboard", "leaderboard") + +@bp.route("/leaderboard") +def leaderboard(): + top_posters = {} + posts = Post.select() + for post in posts: + transfers = [] + incoming = wownero.Wallet().incoming_transfers(post.account_index) + if "transfers" in incoming: + for xfer in incoming["transfers"]: + transfers.append(wownero.from_atomic(xfer["amount"])) + total = sum(transfers) + if post.submitter not in top_posters: + top_posters[post.submitter] = {"amount": 0, "posts": []} + + top_posters[post.submitter]["amount"] += float(total) + top_posters[post.submitter]["posts"].append(post) + + return render_template("leaderboard.html", posters=top_posters) diff --git a/suchwow/templates/index.html b/suchwow/templates/index.html index 7891cc5..ac5be2f 100644 --- a/suchwow/templates/index.html +++ b/suchwow/templates/index.html @@ -24,12 +24,14 @@ Back {% endif %} - {% if page <= total_pages and total_pages > 0 %} + {% if page < total_pages and total_pages > 0 %} Next {% endif %}
- +

Leaderboards

+ + diff --git a/suchwow/templates/leaderboard.html b/suchwow/templates/leaderboard.html new file mode 100644 index 0000000..11371c5 --- /dev/null +++ b/suchwow/templates/leaderboard.html @@ -0,0 +1,23 @@ +{% extends 'base.html' %} + +{% block content %} + +
+ +
+

{% block title %}Top Posters{% endblock %}

+
+ + {% if posters %} + + {% else %} +

No top posters yet!

+ {% endif %} + +
+ +{% endblock %} diff --git a/suchwow/templates/navbar.html b/suchwow/templates/navbar.html index 780463b..0f30072 100755 --- a/suchwow/templates/navbar.html +++ b/suchwow/templates/navbar.html @@ -7,6 +7,9 @@