From 48755ddd6909a2f9576d9f70eed7037648819366 Mon Sep 17 00:00:00 2001 From: Anorak_1 Date: Sun, 30 Oct 2022 17:15:39 +0100 Subject: [PATCH] Modified files: backend.py Added a somewhat janky get request to get the 10 lowest time scores for client --- backend.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/backend.py b/backend.py index 2bb58ca..7aa3772 100644 --- a/backend.py +++ b/backend.py @@ -1,5 +1,6 @@ from flask import Flask from flask_restful import Resource, Api +import sqlite3 app = Flask("LeaderAPI") api = Api(app) @@ -7,7 +8,13 @@ api = Api(app) class LeaderAPI(Resource): def get(self): - return "Hello world!" + dbcon = sqlite3.connect("leaderboard.db") + db = dbcon.cursor() + leaderboard = db.execute("SELECT time_username,time_time FROM leaderboard ORDER BY time_time LIMIT 10").fetchall() + db.close() + dbcon.close() + # dictionary of leaderboard is json, encoding using json.dumps results in double encoding with "" and return to browser as type string + return dict(leaderboard) api.add_resource(LeaderAPI, "/")