Tornado stuff

This commit is contained in:
2019-03-08 11:12:47 +01:00
parent c542c66f7e
commit dc801464ed
7 changed files with 38 additions and 59 deletions

View File

@@ -1,6 +0,0 @@
from os import listdir
handlers = {}
for d in [d.rstrip(".py") for d in listdir(__name__.replace(".", "/")) if d not in ["__init__.py", "__pycache__"]]:
handlers[d] = __import__("%s.%s" % (__name__, d), fromlist=[""])

View File

@@ -1,36 +1,12 @@
import tornado.gen
import tornado.web
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
return callback(method_name, request.args.get(method_name))
def handle(requestsManager.asyncRequestHandler):
return {}
def callback(method, data):
cur = glob.sql.cursor()
if method is "timestamp":
cur.execute("SELECT * FROM updates WHERE timestamp <= '{}' ORDER BY timestamp DESC LIMIT 1".format(
data
))
else:
query = "SELECT * FROM updates WHERE {} = {} LIMIT 1"
if method is "file_hash":
query = "SELECT * FROM updates WHERE {} = '{}' LIMIT 1"
cur.execute(query.format(
method,
data
))
return cur.fetchone()
return None