diff --git a/handlers/getlist.py b/handlers/getlist.py new file mode 100644 index 0000000..a14b82a --- /dev/null +++ b/handlers/getlist.py @@ -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 \ No newline at end of file diff --git a/web.py b/web.py index 43579b2..ddde1a7 100644 --- a/web.py +++ b/web.py @@ -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"]) \ No newline at end of file