mirror of
https://github.com/IgorL123/mafia_api.git
synced 2026-09-23 23:20:19 +00:00
logging & route /
This commit is contained in:
@@ -1,9 +1,27 @@
|
|||||||
from flask import Flask, request, jsonify
|
from flask import Flask, request, jsonify
|
||||||
import db
|
import db
|
||||||
|
import logging
|
||||||
|
from logging.handlers import RotatingFileHandler
|
||||||
import api_functions
|
import api_functions
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
app.logger.handlers.clear()
|
||||||
|
if True:
|
||||||
|
app.logger.setLevel(logging.INFO)
|
||||||
|
file_handler = RotatingFileHandler("log.log", maxBytes=1024 * 1024 * 10)
|
||||||
|
formatter = logging.Formatter(fmt="%(asctime)s - %(message)s")
|
||||||
|
file_handler.setLevel(logging.INFO)
|
||||||
|
file_handler.setFormatter(formatter)
|
||||||
|
app.logger.addHandler(file_handler)
|
||||||
|
app.logger.addHandler(logging.StreamHandler())
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/")
|
||||||
|
def act():
|
||||||
|
app.logger.info("default routing")
|
||||||
|
return "Welcome to Api"
|
||||||
|
|
||||||
|
|
||||||
@app.route('/action', methods=["POST"])
|
@app.route('/action', methods=["POST"])
|
||||||
def action():
|
def action():
|
||||||
@@ -20,7 +38,7 @@ def action():
|
|||||||
"checkedRole": False
|
"checkedRole": False
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor = db.cursor
|
cursor = db.connection.cursor()
|
||||||
|
|
||||||
if killed_user_id != healed_user_id:
|
if killed_user_id != healed_user_id:
|
||||||
cursor.execute(f"Select UserID from chats join userschats uc on uc.chatid = chats.chatid join "
|
cursor.execute(f"Select UserID from chats join userschats uc on uc.chatid = chats.chatid join "
|
||||||
@@ -38,7 +56,7 @@ def action():
|
|||||||
|
|
||||||
response["isEndGame"] = api_functions.isEnd(cursor, true_chat_id)
|
response["isEndGame"] = api_functions.isEnd(cursor, true_chat_id)
|
||||||
db.close(cursor)
|
db.close(cursor)
|
||||||
|
app.logging.info("Actions route")
|
||||||
return jsonify(response), 200
|
return jsonify(response), 200
|
||||||
|
|
||||||
|
|
||||||
@@ -48,6 +66,7 @@ def create():
|
|||||||
tci = request.json['chatID']
|
tci = request.json['chatID']
|
||||||
cursor = db.connection.cursor()
|
cursor = db.connection.cursor()
|
||||||
db.chat_add(tci, cursor)
|
db.chat_add(tci, cursor)
|
||||||
|
app.logger.info("Created new chat")
|
||||||
db.close(cursor)
|
db.close(cursor)
|
||||||
return 'ok', 200
|
return 'ok', 200
|
||||||
|
|
||||||
@@ -57,9 +76,12 @@ def start(): # Команда принимает на вход
|
|||||||
tci = request.json['chatID']
|
tci = request.json['chatID']
|
||||||
user_list = request.json['userIDs']
|
user_list = request.json['userIDs']
|
||||||
cursor = db.connection.cursor()
|
cursor = db.connection.cursor()
|
||||||
|
|
||||||
for current_user in user_list:
|
for current_user in user_list:
|
||||||
db.user_add(current_user, tci, cursor)
|
db.user_add(current_user, tci, cursor)
|
||||||
db.connection.commit()
|
db.connection.commit()
|
||||||
|
app.logger.info(f"Added {len(user_list)} users")
|
||||||
|
|
||||||
db.close(cursor)
|
db.close(cursor)
|
||||||
resp = api_functions.role_distribution(user_list)
|
resp = api_functions.role_distribution(user_list)
|
||||||
return "", resp
|
return "", resp
|
||||||
|
|||||||
Reference in New Issue
Block a user