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
+3 -1
View File
@@ -1 +1,3 @@
venv
venv
setiings.json
.vscode
Binary file not shown.
+20 -1
View File
@@ -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()
app.run()
+36 -12
View File
@@ -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)