setting up poster leaderboard
parent
b5c255cade
commit
db93e5d9f6
@ -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)
|
@ -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 %}
|
Loading…
Reference in New Issue