Untitled

mail@pastecode.io avatar
unknown
python
a month ago
1.2 kB
2
Indexable
Never
from client_manager import ClientManager
from quart import jsonify, request
from loader import app, db
import pickle


clients = [
    # TODO: Сделать получение данных из таблицы clients
    (6928695517, "20883061", "0bb87adc823a86839a8b5ad64e8d2636", "6928695517*****"),
]


@app.before_serving
async def on_startup():
    await db.connect()


@app.after_serving
async def on_shutdown():
    manager.stop_clients()
    await db.disconnect()


@app.route('/send_task', methods=['POST'])
async def send_task():
    data = await request.get_json()
    userbot_id = data.get('userbot_id')
    session_number = data.get('session_number')
    task = data.get('task')

    task_id = await manager.send_task(userbot_id, session_number, task)
    return jsonify({'result': task_id})


@app.route('/get_result', methods=['GET'])
async def get_result():
    userbot_id = int(request.args.get('userbot_id'))
    session_number = int(request.args.get('session_number'))
    task_id = request.args.get('task_id')

    result = await manager.get_result(userbot_id, session_number, task_id)
    return pickle.dumps(result)


if __name__ == "__main__":
    manager = ClientManager(clients)
    app.run(port=7481)
Leave a Comment