[Coffee] [PATCH coffee-flask] Add example for using hiscores functions

Jaroslav Klapalek klapajar at fel.cvut.cz
Wed Sep 26 13:25:29 CEST 2018


---
 app.py | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/app.py b/app.py
index 807f614..d970dcb 100644
--- a/app.py
+++ b/app.py
@@ -157,6 +157,39 @@ def coffee_count():
     return str(db.coffee_count(session.get("uid"), start, stop))
 
 
+ at app.route("/coffee/hiscore")
+ at app.route("/coffee/hiscore/<relweek>")
+def coffee_hiscore(relweek=0):
+    try:
+        int(relweek)
+    except:
+        return ""
+
+    relweek = int(relweek)
+
+    hiscore = db.coffee_weekly_hiscores(week=relweek, limit=5)
+
+    ret = "<style> table.hiscore { counter-reset: count; width: 4in; white-space: nowrap; table-layout: fixed } table.hiscore td { width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } .ol:before { counter-increment: count; content: counter(count) '.' }</style>"
+
+    if hiscore:
+        ret += "<table class=\"hiscore\"><tr><td colspan=\"2\"><b>"
+        if relweek == 0:
+            ret += "This week hiscore:"
+        elif relweek == 1:
+            ret += "Last week hiscore:"
+        else:
+            ret += "Weekly hiscore:"
+        ret += "</b></td></tr>"
+        for (u, c) in hiscore:
+            ret += "<tr><td><span class=\"ol\"></span> %s</td><td>%d</td></tr>" % (u, c)
+        ret += "</table>"
+    else:
+        ret += "<b>Hiscore for this week is empty!</b>"
+
+    #return render_template("hiscore.html", hiscore_data=ret)
+    return ret
+
+
 @app.route('/js')
 def js():
     response = make_response(render_template('main.js'))
-- 
2.7.4




More information about the Coffee mailing list