mirror of
https://github.com/migatu/conjurer.git
synced 2026-07-14 21:38:38 +00:00
Test communication
This commit is contained in:
+14
-15
@@ -1,5 +1,6 @@
|
||||
import logging
|
||||
import threading
|
||||
import json
|
||||
|
||||
from flask import Flask, jsonify, request
|
||||
from waitress import serve
|
||||
@@ -9,20 +10,11 @@ HOST_ADDRESS = "192.168.1.191"
|
||||
PORT_ADDRESS = 5000
|
||||
|
||||
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"])
|
||||
@app.route("/conjurer", methods=["POST"])
|
||||
def answer_external_command():
|
||||
#record = json.loads(request.data)
|
||||
#logger.info(record)
|
||||
#answer_data = "TXT"
|
||||
record = json.loads(request.data)
|
||||
app.logger.info(record)
|
||||
#if "UUID" in record and "QUERY" in record and "AUTHOR" in record:
|
||||
# answer_data = "Query logged"
|
||||
#return_data = (
|
||||
@@ -38,8 +30,8 @@ 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")
|
||||
# trunk-ignore(bandit/B201)
|
||||
app.run(debug=True, use_reloader=False, host=HOST_ADDRESS, port=PORT_ADDRESS)
|
||||
|
||||
|
||||
@@ -51,13 +43,20 @@ def waitress_run(_logger):
|
||||
_logger.info("Attempt waitress")
|
||||
serve(app, host=HOST_ADDRESS, port=PORT_ADDRESS)
|
||||
|
||||
def comm_subroutine():
|
||||
def scan_queue(comm_q):
|
||||
while True:
|
||||
data = comm_q.get()
|
||||
print(data)
|
||||
|
||||
|
||||
def comm_subroutine(comm_q):
|
||||
queue = comm_q
|
||||
logger = logging.getLogger('conjurer_musician')
|
||||
logger.setLevel(logging.DEBUG)
|
||||
logger.info("Started")
|
||||
threads = []
|
||||
threads.append(threading.Thread(target=waitress_run, args=(logger,)))
|
||||
#threads.append(threading.Thread(target=flask_debug, logger))
|
||||
threads.append(threading.Thread(target=scan_queue, args=(queue,)))
|
||||
|
||||
for worker in threads:
|
||||
worker.start()
|
||||
|
||||
Reference in New Issue
Block a user