Fixed typo
This commit is contained in:
parent
0401acd31b
commit
416d7fdd6d
|
@ -29,6 +29,10 @@ class handler(asyncTornado.asyncRequestHandler):
|
|||
args_filter = asyncTornado.check_arguments(self.request.arguments, ARGS)
|
||||
if False in args_filter:
|
||||
raise Exception("Missing required arguments")
|
||||
|
||||
print()
|
||||
print(args_filter)
|
||||
print()
|
||||
|
||||
method = args_filter[0]
|
||||
method_value = self.request.arguments[method]
|
||||
|
@ -44,14 +48,16 @@ class handler(asyncTornado.asyncRequestHandler):
|
|||
cur.execute(sql)
|
||||
data = cur.fetchone()
|
||||
|
||||
cur.close()
|
||||
|
||||
status_code = 200
|
||||
except Exception as e:
|
||||
status_code = 400
|
||||
data["status"] = status_code
|
||||
data["message"] = e
|
||||
finally:
|
||||
cur.close()
|
||||
|
||||
print(data)
|
||||
|
||||
self.write( json.dumps(data) )
|
||||
self.set_header("Content-Type", "application/json")
|
||||
self.set_status(status_code)
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
import json
|
||||
#import MySQLdb
|
||||
#import MySQLdb.cursors
|
||||
from flask import Flask, make_response, request, render_template, jsonify
|
||||
from objects import glob
|
||||
|
||||
import api
|
||||
|
||||
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():
|
||||
return render_template("index.html")
|
||||
|
||||
@app.route("/download")
|
||||
def download_index():
|
||||
return render_template("download.html")
|
||||
|
||||
@app.route("/api")
|
||||
def api_index():
|
||||
return render_template("api.html")
|
||||
|
||||
@app.route("/api/<ver>/<func>")
|
||||
def api_call(ver, func):
|
||||
if ver not in api.versions or func not in api.versions[ver].handlers:
|
||||
return jsonify(api.missing.handle(request))
|
||||
data = api.versions[ver].handlers[func].handle(request)
|
||||
return jsonify(data)
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(**config["web"])
|
19
import_database.py
Normal file
19
import_database.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
if __name__ != "__main__":
|
||||
print("This is not a module")
|
||||
exit()
|
||||
|
||||
import sys
|
||||
import sqlite3
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
print("Missing database import file")
|
||||
exit()
|
||||
|
||||
sql = sqlite3.connect("wayback.db")
|
||||
cur = sql.cursor()
|
||||
|
||||
with open(sys.argv[1], "r") as f:
|
||||
cur.executescript( f.read() )
|
||||
|
||||
cur.close()
|
||||
sql.close()
|
2
main.py
2
main.py
|
@ -40,7 +40,7 @@ def make_app():
|
|||
api = api.rstrip(".py")
|
||||
routes.append(
|
||||
(
|
||||
r"/%s/%s" % (dir, api), __import__("%s.%s" % (dir.replace("/", "."), api), fromlist=[""])
|
||||
r"/%s/%s" % (dir, api), __import__("%s.%s" % (dir.replace("/", "."), api), fromlist=[""]).handler
|
||||
))
|
||||
else:
|
||||
routes += map_routes("%s/%s" % (dir, api))
|
||||
|
|
|
@ -84,7 +84,7 @@ def check_arguments(arguments, arguments_filter):
|
|||
def arg_filter_and(arguments, filter, can_false = False):
|
||||
arg_filter = []
|
||||
for i in filter:
|
||||
if i in filter:
|
||||
if i in arguments:
|
||||
arg_filter.append(i)
|
||||
if can_false:
|
||||
return arg_filter if len(arg_filter) else False
|
||||
|
@ -105,6 +105,6 @@ def arg_filter_only_one(arguments, required):
|
|||
|
||||
def arg_filter_first(arguments, filter, optional = True):
|
||||
for i in filter:
|
||||
if i in filter:
|
||||
if i in arguments:
|
||||
return i
|
||||
return optional
|
||||
|
|
Loading…
Reference in New Issue
Block a user