2022-10-30 15:24:08 +00:00
|
|
|
from flask import Flask
|
|
|
|
from flask_restful import Resource, Api
|
2022-10-30 16:15:39 +00:00
|
|
|
import sqlite3
|
2022-10-30 15:24:08 +00:00
|
|
|
|
|
|
|
app = Flask("LeaderAPI")
|
|
|
|
api = Api(app)
|
|
|
|
|
|
|
|
class LeaderAPI(Resource):
|
|
|
|
|
|
|
|
def get(self):
|
2022-10-30 16:15:39 +00:00
|
|
|
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)
|
2022-10-30 15:24:08 +00:00
|
|
|
|
|
|
|
api.add_resource(LeaderAPI, "/")
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
app.run()
|