mirror of
https://github.com/migatu/conjurer.git
synced 2026-07-15 14:22:13 +00:00
65 lines
1.9 KiB
Python
65 lines
1.9 KiB
Python
import logging
|
|
import threading
|
|
|
|
from flask import Flask, jsonify, request
|
|
from waitress import serve
|
|
|
|
|
|
|
|
app = Flask(__name__)
|
|
@app.route("/mp3", methods=["GET"])
|
|
def get_music_list():
|
|
"""
|
|
The function `get_music_list` returns a JSON object containing a list of music files.
|
|
:return: A JSON response containing a key "music_file_list" with the value of the variable
|
|
`music_file_list`.
|
|
"""
|
|
return jsonify({"music_file_list": MASTER_TIMEOUT})
|
|
|
|
@app.route("/conjurer", methods=["GET"])
|
|
def answer_external_command():
|
|
#record = json.loads(request.data)
|
|
#logger.info(record)
|
|
#answer_data = "TXT"
|
|
#if "UUID" in record and "QUERY" in record and "AUTHOR" in record:
|
|
# answer_data = "Query logged"
|
|
#return_data = (
|
|
# jsonify(isError=False, message="Success", statusCode=200, data=answer_data),
|
|
# 200,
|
|
#)
|
|
#return return_data
|
|
return jsonify("SUCCESS")
|
|
|
|
|
|
def flask_debug(_logger):
|
|
"""
|
|
The `flask_debug` function starts a Flask application in debug mode without using the reloader.
|
|
Do not use for production for fucks sake.
|
|
"""
|
|
# trunk-ignore(bandit/B201)
|
|
_logger.info("Attempt debug")
|
|
app.run(debug=True, use_reloader=False, host=HOST_ADDRESS, port=PORT_ADDRESS, logger=_logger)
|
|
|
|
|
|
def waitress_run(_logger):
|
|
"""
|
|
The `waitress_run` function serves the `app` on host "0.0.0.0"
|
|
and port 5000 using the Waitress WSGI server.
|
|
"""
|
|
_logger.info("Attempt waitress")
|
|
serve(app, host=HOST_ADDRESS, port=PORT_ADDRESS, logger=_logger)
|
|
|
|
if __name__ == "__main__":
|
|
logger = logging.getLogger('conjurer_musician')
|
|
logger.setLevel(logging.DEBUG)
|
|
logger.info("Started")
|
|
threads = []
|
|
threads.append(threading.Thread(target=waitress_run, logger=logger))
|
|
#threads.append(threading.Thread(target=flask_debug, logger=logger))
|
|
|
|
for worker in threads:
|
|
worker.start()
|
|
|
|
for worker in threads:
|
|
worker.join()
|