setting up poster leaderboard

graphs-n-shit
lza_menace 4 years ago
parent b5c255cade
commit db93e5d9f6

@ -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():

@ -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)

@ -24,12 +24,14 @@
<a href="/?page={{ page - 1 }}" style="padding:1em;">Back</a>
{% endif %}
{% if page <= total_pages and total_pages > 0 %}
{% if page < total_pages and total_pages > 0 %}
<a href="/?page={{ page + 1 }}" style="padding:1em;">Next</a>
{% endif %}
<hr>
<a href="{{ url_for('post.top') }}"><button class="btn btn-warning">See Top Posts</button></a>
<h3>Leaderboards</h3>
<a href="{{ url_for('post.top') }}"><button class="btn btn-warning">Top Posts</button></a>
<a href="{{ url_for('leaderboard.leaderboard') }}"><button class="btn btn-warning">Top Posters</button></a>
</div>

@ -0,0 +1,23 @@
{% extends 'base.html' %}
{% block content %}
<div class="container" style="text-align:center;">
<div class="title">
<h3>{% block title %}Top Posters{% endblock %}</h3>
</div>
{% if posters %}
<ul style="list-style-type:none;">
{% for poster, data in posters.items() | sort(attribute='1.amount', reverse=True) %}
<li>{{ poster }} - {% for post in data["posts"] %}<a href="{{ url_for('post.read', id=post.id) }}">{{ post }}</a>, {% endfor %} - {{ data["amount"] }} WOW received</li>
{% endfor %}
</ul>
{% else %}
<p>No top posters yet!</p>
{% endif %}
</div>
{% endblock %}

@ -7,6 +7,9 @@
<div class="" id="">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="{{ url_for('index') }}">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ url_for('post.create') }}">Submit</a>
</li>

Loading…
Cancel
Save