osu-wayback/api/v1/_getList.py

31 lines
835 B
Python
Raw Normal View History

2018-05-31 11:18:23 +02:00
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
2018-05-31 11:23:04 +02:00
return callback(method_name)
2018-05-31 11:18:23 +02:00
2018-05-31 11:23:04 +02:00
def callback(method):
2018-05-31 11:18:23 +02:00
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