mirror of
https://github.com/IgorL123/mafia_api.git
synced 2026-09-23 23:20:19 +00:00
ready create
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from flask import Flask, request
|
||||
# import db
|
||||
import db
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@@ -11,8 +11,10 @@ def hello_world(): # put application's code here
|
||||
|
||||
@app.route('/create_game', methods=["POST"])
|
||||
def create():
|
||||
TCI = request.json
|
||||
db.query_ins_chat(TCI)
|
||||
TCI = request.json['chatID']
|
||||
curs = db.conn()
|
||||
db.query_ins_chat(TCI, curs)
|
||||
db.close(curs)
|
||||
|
||||
|
||||
@app.route('/start_game')
|
||||
|
||||
@@ -8,30 +8,34 @@ db_params = {
|
||||
'password': '4oumQk'
|
||||
}
|
||||
|
||||
connection = psycopg2.connect(**db_params)
|
||||
cursor = connection.cursor()
|
||||
# connection = psycopg2.connect(**db_params) #запускаем один раз
|
||||
|
||||
|
||||
def query_ins_user(x, curs=cursor):
|
||||
def conn(conn=connection):
|
||||
cursor = conn.cursor()
|
||||
return cursor
|
||||
|
||||
|
||||
def query_ins_user(tui, curs=cursor):
|
||||
try:
|
||||
# Запрос добавления пользователя
|
||||
curs.execute(
|
||||
f"""INSERT into public.Users(TrueUserID, role, isAlive) values ({x}, 0)""")
|
||||
curs.commit()
|
||||
f"""INSERT into public.Users(TrueUserID, role, isAlive) values ({tui}, 0)""")
|
||||
conn.commit()
|
||||
except Exception as e:
|
||||
print("Ошибка:", e)
|
||||
|
||||
|
||||
def query_ins_chat(x, curs=cursor):
|
||||
def query_ins_chat(tci, curs=cursor):
|
||||
try: # Запрос добавления чата
|
||||
curs.execute(
|
||||
f"""INSERT into public.Chats(TrueChatID, StateID) values ({x}, 0)""")
|
||||
curs.commit()
|
||||
f"""INSERT into public.Chats(TrueChatID, StateID) values ({tci}, 0)""")
|
||||
conn.commit()
|
||||
except Exception as e:
|
||||
print("Ошибка:", e)
|
||||
|
||||
|
||||
def query_sel(x, curs=cursor):
|
||||
def query_sel(query, curs=cursor):
|
||||
try:
|
||||
# Запрос вывода из БД
|
||||
curs.execute("SELECT * FROM chats")
|
||||
@@ -51,4 +55,3 @@ def query_change(x):
|
||||
|
||||
def close(cur=cursor, conn=connection):
|
||||
cursor.close()
|
||||
connection.close()
|
||||
|
||||
Reference in New Issue
Block a user