mirror of
https://github.com/IgorL123/mafia_api.git
synced 2026-09-23 23:20:19 +00:00
@@ -1 +1,3 @@
|
||||
venv
|
||||
setiings.json
|
||||
.vscode
|
||||
Binary file not shown.
@@ -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()
|
||||
@@ -9,22 +9,46 @@ db_params = {
|
||||
}
|
||||
|
||||
|
||||
connection = psycopg2.connect(**db_params) # запускаем один раз
|
||||
|
||||
|
||||
def query_ins_user(tui, curs):
|
||||
try:
|
||||
connection = psycopg2.connect(**db_params)
|
||||
cursor = connection.cursor()
|
||||
# Запрос добавления пользователя
|
||||
curs.execute(
|
||||
f"""INSERT into public.Users(TrueUserID, role, isAlive) values ({tui}, 0)""")
|
||||
connection.commit()
|
||||
except Exception as e:
|
||||
print("Ошибка:", e)
|
||||
|
||||
# Ваш код выполнения запросов
|
||||
|
||||
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_chat(tci, curs):
|
||||
try: # Запрос добавления чата
|
||||
curs.execute(
|
||||
f"""INSERT into public.Chats(TrueChatID, StateID) values ({tci}, 0)""")
|
||||
connection.commit()
|
||||
except Exception as e:
|
||||
print("Ошибка:", e)
|
||||
|
||||
rows = cursor.fetchall()
|
||||
|
||||
for row in rows:
|
||||
print(row)
|
||||
def query_sel(query, curs):
|
||||
try:
|
||||
# Запрос вывода из БД
|
||||
curs.execute("SELECT * FROM chats")
|
||||
rows = curs.fetchall()
|
||||
|
||||
cursor.close()
|
||||
connection.close()
|
||||
# for row in rows:
|
||||
# print(row)
|
||||
|
||||
except Exception as e:
|
||||
print("Ошибка:", e)
|
||||
|
||||
|
||||
def query_change(x):
|
||||
# Написать выдачу резов по ролям
|
||||
pass
|
||||
|
||||
|
||||
def close(cur):
|
||||
cursor.close()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user