gemini-boggle/rank.cgi

34 lines
716 B
Python
Executable File

#!/usr/bin/env python3
import random
from helpers import get_client_cert
from db import *
TLS_CLIENT_HASH = get_client_cert()
user_id = check_hash(TLS_CLIENT_HASH)
user_name = get_name(user_id) or "[Not Set]"
game_id = get_game_id(user_id)
if game_id:
print("=> game.cgi back to game")
print("=> lobby.cgi lobby")
print("=> login.cgi login")
print("=> new_game.cgi new game")
conn=create_connection()
with conn:
cur = conn.cursor()
cur.execute("SELECT name,score FROM users WHERE score>0 ORDER BY score DESC")
rows = cur.fetchall()
print("# Ranking")
print("```")
rank=1
print(f"rank score name")
for row in rows:
print(f"{rank:4d} {row[1]:5d} {row[0]:32s}")
rank+=1
print("```")