Merge pull request #2 from ada-dmitry/adamain

Create_game Ready
This commit is contained in:
IgorL123
2023-08-22 17:02:31 +03:00
committed by GitHub
4 changed files with 59 additions and 14 deletions
+2
View File
@@ -1 +1,3 @@
venv venv
setiings.json
.vscode
Binary file not shown.
+19
View File
@@ -2,6 +2,7 @@ from flask import Flask, request, jsonify
import db import db
import api_functions import api_functions
app = Flask(__name__) app = Flask(__name__)
@@ -39,5 +40,23 @@ def action(): # put application's code here
return jsonify(response), 200 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__': if __name__ == '__main__':
app.run() app.run()
+40 -16
View File
@@ -9,22 +9,46 @@ db_params = {
} }
try: connection = psycopg2.connect(**db_params) # запускаем один раз
connection = psycopg2.connect(**db_params)
cursor = connection.cursor()
# Ваш код выполнения запросов
cursor.execute(f"Select role from chats join userschats uc on uc.chatid = " def query_ins_user(tui, curs):
f"chats.chatid join users on users.userid = uc.userid where truechatid = '{7656}' and isAlive = true") try:
# Запрос добавления пользователя
rows = cursor.fetchall() curs.execute(
f"""INSERT into public.Users(TrueUserID, role, isAlive) values ({tui}, 0)""")
for row in rows: connection.commit()
print(row) except Exception as e:
cursor.close()
connection.close()
except Exception as e:
print("Ошибка:", e) print("Ошибка:", e)
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()