Почти полностью рабочая версия
This commit is contained in:
@@ -19,6 +19,7 @@ os.makedirs("logs", exist_ok=True)
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
format="%(asctime)s | %(levelname)s | %(name)s | %(message)s",
|
||||
datefmt="%Y-%m-%d %H:%M:%S",
|
||||
handlers=[
|
||||
logging.FileHandler(Config.LOG_FILE, encoding="utf-8"),
|
||||
logging.StreamHandler(),
|
||||
@@ -28,6 +29,14 @@ logging.basicConfig(
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def getLogs():
|
||||
from collections import deque
|
||||
|
||||
with open(Config.LOG_FILE, "r", encoding="utf-8") as f:
|
||||
last_lines = deque(f, maxlen=500)
|
||||
return "".join(reversed(last_lines))
|
||||
|
||||
|
||||
@app.before_request
|
||||
def init():
|
||||
db.create_all()
|
||||
@@ -35,9 +44,79 @@ def init():
|
||||
logger.info("Приложение запущено")
|
||||
|
||||
|
||||
@app.route("/")
|
||||
@app.route("/", methods=["GET", "POST"])
|
||||
def index():
|
||||
return render_template("index.html")
|
||||
match request.method:
|
||||
case "GET":
|
||||
exitData = {}
|
||||
medodsApi = MedodsAPI.query.first()
|
||||
if medodsApi:
|
||||
exitData["medodsApi"] = {
|
||||
"updated_at": medodsApi.updated_at.strftime("%Y-%m-%d %H:%M:%S")
|
||||
}
|
||||
if medodsApi.url:
|
||||
exitData["medodsApi"]["url"] = True
|
||||
else:
|
||||
exitData["medodsApi"]["url"] = False
|
||||
if medodsApi.identity and medodsApi.secretKey:
|
||||
exitData["medodsApi"]["apiKey"] = True
|
||||
else:
|
||||
exitData["medodsApi"]["apiKey"] = False
|
||||
apiEndpointsCount = ApiEndpoint.query.count()
|
||||
exitData["medodsApi"]["apiEndpointsCount"] = apiEndpointsCount
|
||||
vkApi = VkAPI.query.first()
|
||||
if vkApi:
|
||||
exitData["vkApi"] = {
|
||||
"updated_at": vkApi.updated_at.strftime("%Y-%m-%d %H:%M:%S")
|
||||
}
|
||||
if vkApi.group_id:
|
||||
exitData["vkApi"]["group_id"] = True
|
||||
else:
|
||||
exitData["vkApi"]["group_id"] = False
|
||||
if vkApi.access_token:
|
||||
exitData["vkApi"]["access_token"] = True
|
||||
else:
|
||||
exitData["vkApi"]["access_token"] = False
|
||||
if vkApi.base_photo_url:
|
||||
exitData["vkApi"]["base_photo_url"] = True
|
||||
else:
|
||||
exitData["vkApi"]["base_photo_url"] = False
|
||||
vkPost = VkPost.query.first()
|
||||
if vkPost:
|
||||
exitData["vkPost"] = {
|
||||
"updated_at": vkPost.updated_at.strftime("%Y-%m-%d %H:%M:%S")
|
||||
}
|
||||
if vkPost.static_text:
|
||||
exitData["vkPost"]["static_text"] = True
|
||||
else:
|
||||
exitData["vkPost"]["static_text"] = False
|
||||
if vkPost.selected_users:
|
||||
exitData["vkPost"]["selected_users"] = len(vkPost.selected_users)
|
||||
else:
|
||||
exitData["vkPost"]["selected_users"] = False
|
||||
if vkPost.full_name is not None:
|
||||
exitData["vkPost"]["full_name"] = vkPost.full_name
|
||||
if vkPost.post_id and vkApi and vkApi.group_id:
|
||||
exitData["vkPost"][
|
||||
"post_link"
|
||||
] = f"https://vk.com/wall-{vkApi.group_id}_{vkPost.post_id}"
|
||||
else:
|
||||
exitData["vkPost"]["post_link"] = False
|
||||
if vkPost.publish_at:
|
||||
exitData["vkPost"]["publish_at"] = vkPost.publish_at.strftime(
|
||||
"%Y-%m-%d %H:%M:%S"
|
||||
)
|
||||
else:
|
||||
exitData["vkPost"]["publish_at"] = False
|
||||
usersMedods = UsersMedods.query.count()
|
||||
exitData["vkPost"]["usersMedods"] = usersMedods
|
||||
exitData["vkPost"]["scheduler"] = get_scheduler_status()
|
||||
|
||||
return render_template("index.html", exitData=exitData)
|
||||
case "POST":
|
||||
return jsonify(logs=getLogs())
|
||||
case _:
|
||||
return "Method not allowed", 405
|
||||
|
||||
|
||||
@app.route("/medods", methods=["GET"])
|
||||
|
||||
Reference in New Issue
Block a user