stuff
This commit is contained in:
parent
af8e618f01
commit
7589408812
2 changed files with 63 additions and 48 deletions
96
main.py
96
main.py
|
@ -1,6 +1,6 @@
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
__version__="0.0"
|
__version__ = "0.0"
|
||||||
|
|
||||||
from flask import Flask as wserv
|
from flask import Flask as wserv
|
||||||
|
|
||||||
|
@ -9,66 +9,68 @@ app = wserv('superTinySearch API Runtime')
|
||||||
from flask import render_template
|
from flask import render_template
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
debugmode=False
|
|
||||||
|
debugmode = False
|
||||||
if "debug" in sys.argv:
|
if "debug" in sys.argv:
|
||||||
debugmode=True
|
debugmode = True
|
||||||
del sys
|
del sys
|
||||||
|
|
||||||
|
|
||||||
def makeServerHeader():
|
def makeServerHeader():
|
||||||
import sys
|
import sys
|
||||||
return f"superTinySearch API/{__version__} (Unix) (Python v{sys.version})"
|
return f"superTinySearch API/{__version__} (Unix) (Python v{sys.version})"
|
||||||
|
|
||||||
|
|
||||||
# @app.errorhandler(404)
|
# @app.errorhandler(404)
|
||||||
# def not_found(error):
|
# def not_found(error):
|
||||||
# from flask import request as rq
|
# from flask import request as rq
|
||||||
# if rq.args.get('returnFormat','') == "xml"
|
# if rq.args.get('returnFormat','') == "xml"
|
||||||
|
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def noHumans():
|
def noHumans():
|
||||||
from flask import Response
|
from flask import Response
|
||||||
resp=Response(
|
resp = Response(response="running", status=200, mimetype="text/plain")
|
||||||
response="running",
|
resp.headers["Server"] = makeServerHeader
|
||||||
status=200,
|
resp.headers["Accept"] = "text/plain"
|
||||||
mimetype="text/plain"
|
return resp
|
||||||
)
|
|
||||||
resp.headers["Server"] = makeServerHeader
|
|
||||||
resp.headers["Accept"] = "text/plain"
|
|
||||||
return resp
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/about")
|
@app.route("/about")
|
||||||
def aboutThis():
|
def aboutThis():
|
||||||
from flask import Response
|
|
||||||
resp=Response(
|
|
||||||
response=f"superTinySearch API v{__version__}",
|
|
||||||
status=200,
|
|
||||||
mimetype="text/plain"
|
|
||||||
)
|
|
||||||
resp.headers["Server"] = makeServerHeader
|
|
||||||
resp.headers["Accept"] = "text/plain"
|
|
||||||
return resp
|
|
||||||
|
|
||||||
@app.route("/apifront?returnFormat=<rf>&srcHostname=<src>", methods=['GET','POST'])
|
|
||||||
def apiRun(rf = 'xml', src = None):
|
|
||||||
from flask import request as rq
|
|
||||||
if rq.method == 'GET':
|
|
||||||
return 'GET REQUESTS NOT ALLOWED'
|
|
||||||
else:
|
|
||||||
from src import frontend
|
|
||||||
out=frontend.parsePOST(rq.form.to_dict(flat=False),rf,src)
|
|
||||||
del frontend
|
|
||||||
from flask import Response
|
from flask import Response
|
||||||
resp = Response(response=out.content, status=500, mime="text/plain")
|
resp = Response(response=f"superTinySearch API v{__version__}",
|
||||||
if rf == "xml":
|
status=200,
|
||||||
resp.headers["Content-Type"] = "text/xml; charset=utf-8"
|
mimetype="text/plain")
|
||||||
elif rf == "json":
|
resp.headers["Server"] = makeServerHeader
|
||||||
resp.headers["Content-Type"] = "application/json; charset=utf-8"
|
resp.headers["Accept"] = "text/plain"
|
||||||
else:
|
|
||||||
resp.headers["Content-Type"] = "text/plain; charset=utf-8"
|
|
||||||
resp.headers["Server"] = makeServerHeader()
|
|
||||||
resp.status=200
|
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/apifront?returnFormat=<rf>&srcHostname=<src>",
|
||||||
|
methods=['GET', 'POST'])
|
||||||
|
def apiRun(rf='xml', src=None):
|
||||||
|
from flask import request as rq
|
||||||
|
if rq.method == 'GET':
|
||||||
|
return 'GET REQUESTS NOT ALLOWED'
|
||||||
|
else:
|
||||||
|
from src import frontend
|
||||||
|
out = frontend.parsePOST(rq.form.to_dict(flat=False), rf, src)
|
||||||
|
del frontend
|
||||||
|
from flask import Response
|
||||||
|
resp = Response(response=out.content, status=500, mime="text/plain")
|
||||||
|
if rf == "xml":
|
||||||
|
resp.headers["Content-Type"] = "text/xml; charset=utf-8"
|
||||||
|
elif rf == "json":
|
||||||
|
resp.headers["Content-Type"] = "application/json; charset=utf-8"
|
||||||
|
else:
|
||||||
|
resp.headers["Content-Type"] = "text/plain; charset=utf-8"
|
||||||
|
resp.headers["Server"] = makeServerHeader()
|
||||||
|
resp.status = 200
|
||||||
|
return resp
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(host="0.0.0.0",port=443)
|
app.run(host="0.0.0.0", port=443)
|
||||||
else:
|
else:
|
||||||
raise "INVALID USAGE OF API APP"
|
raise "INVALID USAGE OF API APP"
|
||||||
|
|
|
@ -40,7 +40,20 @@ class Accessor:
|
||||||
""")
|
""")
|
||||||
self.buffers.db.commit()
|
self.buffers.db.commit()
|
||||||
return True
|
return True
|
||||||
|
def removeEntry(self, filters):
|
||||||
|
if self.mode == "ro":
|
||||||
|
raise ImportError
|
||||||
|
self._refresh()
|
||||||
|
query="DELETE FROM index WHERE "
|
||||||
|
if filters.full:
|
||||||
|
query+=f"fullURL = {filters.fullURL}"
|
||||||
|
elif filters.hostname:
|
||||||
|
query+=f"fullURL LIKE %{filters.hostname}%"
|
||||||
|
|
||||||
|
query+=";"
|
||||||
|
self.buffers.dbcursor.execute(query)
|
||||||
|
self.buffers.db.commit()
|
||||||
|
return True
|
||||||
def __init__(self, mode="ro"):
|
def __init__(self, mode="ro"):
|
||||||
self.mode = mode
|
self.mode = mode
|
||||||
self.search = {'query': None, 'limit': 20, 'offset': 0}
|
self.search = {'query': None, 'limit': 20, 'offset': 0}
|
||||||
|
|
Loading…
Reference in a new issue