Added getList endpoint

This commit is contained in:
Emily 2018-05-31 11:18:23 +02:00
parent 807c06504f
commit 9f74fdeae5
2 changed files with 41 additions and 1 deletions

35
handlers/getlist.py Normal file
View File

@ -0,0 +1,35 @@
from objects import glob
allowed_args = ["file_hash", "file_version", "timestamp"]
def handle(request):
if len([x for x in request.args if x in allowed_args]) == 0:
return {
"error": "Missing valid args",
"allowed": allowed_args
}
for i in range(len(allowed_args)): # Gets the first valid argument and sets it as the method handler
method = request.args.get(allowed_args[i])
method_name = allowed_args[i]
if method is not None:
break
output = {
"method": method_name,
"response": callback(method_name, request.args.get(method_name))
}
return output
def callback(method, data):
cur = glob.sql.cursor()
cur.execute("SELECT {} FROM updates WHERE filename = 'osu!.exe' ORDER BY file_version".format(
method
))
data = []
for row in cur.fetchall():
data.append(row[method])
return data

7
web.py
View File

@ -2,7 +2,7 @@ import json
import MySQLdb
import MySQLdb.cursors
from flask import Flask, make_response, request, render_template, jsonify
from handlers import getupdate, getfile
from handlers import getupdate, getfile, getlist
from objects import glob
app = Flask(__name__)
@ -36,5 +36,10 @@ def api_file():
data = getfile.handle(request)
return jsonify(data)
@app.route("/api/getList", methods=["GET", "POST"])
def api_list():
data = getlist.handle(request)
return jsonify(data)
if __name__ == "__main__":
app.run(**config["web"])