Added getUpdate endpoint
This commit is contained in:
parent
3e9a7d05d7
commit
8752f2a431
|
@ -1,3 +1,5 @@
|
|||
from objects import glob
|
||||
|
||||
allowed_args = ["file_hash", "file_version", "timestamp"]
|
||||
|
||||
def handle(request):
|
||||
|
@ -11,7 +13,22 @@ def handle(request):
|
|||
break
|
||||
|
||||
output = {
|
||||
"search_method": method_name
|
||||
"method": method_name,
|
||||
"response": callback(method_name, request.args.get(method_name))
|
||||
}
|
||||
output["endpoint"] = request.endpoint
|
||||
return output
|
||||
return output
|
||||
|
||||
def callback(method, data):
|
||||
cur = glob.sql.cursor()
|
||||
|
||||
if method is "file_hash":
|
||||
cur.execute("SELECT * FROM updates WHERE file_hash = '{}'".format(
|
||||
data
|
||||
))
|
||||
else:
|
||||
cur.execute("SELECT a.* FROM updates a INNER JOIN ( SELECT MAX(file_version) file_version, filename FROM updates WHERE {} < {} GROUP BY filename) b ON a.file_version = b.file_version;".format(
|
||||
method,
|
||||
data
|
||||
))
|
||||
|
||||
return cur.fetchall()
|
1
objects/glob.py
Normal file
1
objects/glob.py
Normal file
|
@ -0,0 +1 @@
|
|||
sql = None
|
8
web.py
8
web.py
|
@ -3,12 +3,16 @@ import MySQLdb
|
|||
import MySQLdb.cursors
|
||||
from flask import Flask, make_response, request, render_template, jsonify
|
||||
from handlers import update
|
||||
from objects import glob
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
with open("config.json", "r") as f:
|
||||
config = json.load(f)
|
||||
|
||||
# Setup sql
|
||||
glob.sql = MySQLdb.connect(**config["sql"], cursorclass = MySQLdb.cursors.DictCursor)
|
||||
|
||||
@app.route("/")
|
||||
@app.route("/home")
|
||||
def home_index():
|
||||
|
@ -26,9 +30,5 @@ def api_index():
|
|||
def api_update():
|
||||
return update.handle(request)
|
||||
|
||||
@app.route("/api")
|
||||
def api_index():
|
||||
return render_template("api.html")
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(**config["web"])
|
Loading…
Reference in New Issue
Block a user