mirror of
https://github.com/migatu/conjurer.git
synced 2026-07-18 07:42:09 +00:00
test
This commit is contained in:
@@ -38,9 +38,7 @@ import requests
|
|||||||
import spotipy
|
import spotipy
|
||||||
import tiktoken
|
import tiktoken
|
||||||
from discord.ext import commands, tasks
|
from discord.ext import commands, tasks
|
||||||
from flask import Flask, jsonify, request
|
|
||||||
from spotipy.oauth2 import SpotifyClientCredentials
|
from spotipy.oauth2 import SpotifyClientCredentials
|
||||||
from waitress import serve
|
|
||||||
|
|
||||||
import yt_dlp
|
import yt_dlp
|
||||||
from spotify_dl import spotify
|
from spotify_dl import spotify
|
||||||
@@ -2212,59 +2210,15 @@ async def krecimy_pornola(ctx):
|
|||||||
else:
|
else:
|
||||||
ctx.reply("Jak ładnie szefa poprosisz.")
|
ctx.reply("Jak ładnie szefa poprosisz.")
|
||||||
|
|
||||||
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)
|
|
||||||
t2 = threading.Thread(target=flask_debug, args=(logger,))
|
|
||||||
t2.start()
|
|
||||||
t2.join()
|
|
||||||
|
|
||||||
# *================================== Run
|
# *================================== Run
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# TODO: wpakowac kondzia w wątki odpalic asynchronicznie rownolegle z flaskiem do sterowania nim
|
# TODO: wpakowac kondzia w wątki odpalic asynchronicznie rownolegle z flaskiem do sterowania nim
|
||||||
logger.info("Starting discord bot")
|
logger.info("Starting discord bot")
|
||||||
threads = []
|
threads = []
|
||||||
t1 = threading.Thread(target=client.run, args=(TOKEN,))
|
threads.append(threading.Thread(target=client.run, args=(TOKEN,)))
|
||||||
t1.start()
|
|
||||||
t1.join()
|
|
||||||
|
|
||||||
# widok - generuje się 5 stron po 4 linki
|
# widok - generuje się 5 stron po 4 linki
|
||||||
# odśwież - zamienić na "dalej" - zaciąga kolejne 20 rezultatów
|
# odśwież - zamienić na "dalej" - zaciąga kolejne 20 rezultatów
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
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))
|
||||||
|
#threads.append(threading.Thread(target=thread_rescan))
|
||||||
|
|
||||||
|
for worker in threads:
|
||||||
|
worker.start()
|
||||||
|
|
||||||
|
for worker in threads:
|
||||||
|
worker.join()
|
||||||
Reference in New Issue
Block a user