diff --git a/.gitignore b/.gitignore index f5e96db..6b638aa 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -venv \ No newline at end of file +venv +setiings.json +.vscode \ No newline at end of file diff --git a/__pycache__/db.cpython-311.pyc b/__pycache__/db.cpython-311.pyc new file mode 100644 index 0000000..bf498f9 Binary files /dev/null and b/__pycache__/db.cpython-311.pyc differ diff --git a/app.py b/app.py index 58031fc..5361a26 100644 --- a/app.py +++ b/app.py @@ -2,6 +2,7 @@ from flask import Flask, request, jsonify import db import api_functions + app = Flask(__name__) @@ -39,5 +40,23 @@ def action(): # put application's code here return jsonify(response), 200 +@app.route('/create_game', methods=["POST"]) +def create(): + TCI = request.json['chatID'] + cursor = db.connection.cursor() + db.query_ins_chat(TCI, cursor) + db.close(cursor) + + +@app.route('/start_game') +def start(): # Команда принимает на вход + pass + + +@app.route('/action') +def action(): + pass + + if __name__ == '__main__': - app.run() \ No newline at end of file + app.run() diff --git a/db.py b/db.py index 4ece3e4..43d3b4f 100644 --- a/db.py +++ b/db.py @@ -9,22 +9,46 @@ db_params = { } -try: - connection = psycopg2.connect(**db_params) - cursor = connection.cursor() +connection = psycopg2.connect(**db_params) # запускаем один раз - # Ваш код выполнения запросов - cursor.execute(f"Select role from chats join userschats uc on uc.chatid = " - f"chats.chatid join users on users.userid = uc.userid where truechatid = '{7656}' and isAlive = true") +def query_ins_user(tui, curs): + try: + # Запрос добавления пользователя + curs.execute( + f"""INSERT into public.Users(TrueUserID, role, isAlive) values ({tui}, 0)""") + connection.commit() + except Exception as e: + print("Ошибка:", e) - rows = cursor.fetchall() - for row in rows: - print(row) +def query_ins_chat(tci, curs): + try: # Запрос добавления чата + curs.execute( + f"""INSERT into public.Chats(TrueChatID, StateID) values ({tci}, 0)""") + connection.commit() + except Exception as e: + print("Ошибка:", e) + +def query_sel(query, curs): + try: + # Запрос вывода из БД + curs.execute("SELECT * FROM chats") + rows = curs.fetchall() + + # for row in rows: + # print(row) + + except Exception as e: + print("Ошибка:", e) + + +def query_change(x): + # Написать выдачу резов по ролям + pass + + +def close(cur): cursor.close() - connection.close() -except Exception as e: - print("Ошибка:", e)