api autodoc path
This commit is contained in:
parent
ccd04ba7fb
commit
aa0c9b401e
26
helpers/apiDocumentationHelper.py
Normal file
26
helpers/apiDocumentationHelper.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
import json
|
||||
|
||||
import tornado.gen
|
||||
import tornado.web
|
||||
|
||||
from web import asyncTornado
|
||||
|
||||
from objects import glob
|
||||
|
||||
class handler(asyncTornado.asyncRequestHandler):
|
||||
@tornado.web.asynchronous
|
||||
@tornado.gen.engine
|
||||
def asyncGet(self):
|
||||
url = "/".join( [x for x in self.request.uri.split("/")][:-1] )
|
||||
ver = self.request.uri.split("/")[-1]
|
||||
|
||||
data = {
|
||||
"browse": ver,
|
||||
"apis": [
|
||||
x[0] for x in glob.routes if x[0].startswith("%s/%s/" % (url, ver))
|
||||
]
|
||||
}
|
||||
|
||||
self.write( json.dumps(data) )
|
||||
self.set_header("Content-Type", "application/json")
|
||||
self.set_status(200)
|
9
main.py
9
main.py
|
@ -8,6 +8,7 @@ import tornado.ioloop
|
|||
import tornado.web
|
||||
import tornado.netutil
|
||||
|
||||
from helpers import apiDocumentationHelper as doc_api
|
||||
|
||||
from objects import glob
|
||||
|
||||
|
@ -31,9 +32,9 @@ def make_app():
|
|||
Map out a directory array of modules in a given directory
|
||||
|
||||
:param str: directory to map out and import
|
||||
:return: tuple( endpoint, module.handle )[] routes
|
||||
:return: tuple( endpoint, module.handler )[] routes
|
||||
"""
|
||||
routes = []
|
||||
routes = [(r"/%s" % dir, doc_api.handler)]
|
||||
apis = get_files(dir)
|
||||
for api in apis:
|
||||
if api.endswith(".py"):
|
||||
|
@ -46,8 +47,8 @@ def make_app():
|
|||
routes += map_routes("%s/%s" % (dir, api))
|
||||
return routes
|
||||
|
||||
routes = map_routes("api")
|
||||
return tornado.web.Application(routes)
|
||||
glob.routes = map_routes("api")
|
||||
return tornado.web.Application(glob.routes)
|
||||
|
||||
def build_database():
|
||||
f = open("wayback.db", "w")
|
||||
|
|
|
@ -6,6 +6,7 @@ from helpers import databaseHelper
|
|||
with open("config.json", "r") as f:
|
||||
config = json.load(f)
|
||||
|
||||
routes = []
|
||||
app = None
|
||||
sql = None
|
||||
pool = ThreadPool(config["threads"])
|
||||
|
|
Loading…
Reference in New Issue
Block a user