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