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 %}
No top posters yet!
+ {% endif %} + +