From 416d7fdd6dba35e82ba3a92a553a43fc35734408 Mon Sep 17 00:00:00 2001 From: Sunpy Date: Mon, 11 Mar 2019 07:27:54 +0100 Subject: [PATCH] Fixed typo --- api/v1/{getList.py => _getList.py} | 0 api/v1/{getUpdate.py => _getUpdate.py} | 0 api/v1/getFile.py | 10 +++++-- flask_main.py | 38 -------------------------- import_database.py | 19 +++++++++++++ main.py | 2 +- web/asyncTornado.py | 4 +-- 7 files changed, 30 insertions(+), 43 deletions(-) rename api/v1/{getList.py => _getList.py} (100%) rename api/v1/{getUpdate.py => _getUpdate.py} (100%) delete mode 100644 flask_main.py create mode 100644 import_database.py diff --git a/api/v1/getList.py b/api/v1/_getList.py similarity index 100% rename from api/v1/getList.py rename to api/v1/_getList.py diff --git a/api/v1/getUpdate.py b/api/v1/_getUpdate.py similarity index 100% rename from api/v1/getUpdate.py rename to api/v1/_getUpdate.py diff --git a/api/v1/getFile.py b/api/v1/getFile.py index 0f04e31..6dab909 100644 --- a/api/v1/getFile.py +++ b/api/v1/getFile.py @@ -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) diff --git a/flask_main.py b/flask_main.py deleted file mode 100644 index 445082f..0000000 --- a/flask_main.py +++ /dev/null @@ -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//") -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"]) \ No newline at end of file diff --git a/import_database.py b/import_database.py new file mode 100644 index 0000000..77c8c1e --- /dev/null +++ b/import_database.py @@ -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() \ No newline at end of file diff --git a/main.py b/main.py index 2c09d42..a0f3a10 100644 --- a/main.py +++ b/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)) diff --git a/web/asyncTornado.py b/web/asyncTornado.py index 59cda8c..fc0ed82 100644 --- a/web/asyncTornado.py +++ b/web/asyncTornado.py @@ -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