From 1c14fa794206df2b526fe185777fe5d9f6996acd Mon Sep 17 00:00:00 2001 From: cuiweizhi <560397@gree.com.cn> Date: Sun, 12 Nov 2023 21:31:29 +0800 Subject: [PATCH] Update project --- application/config/config.yaml | 2 +- application/libs/helper/__init__.py | 1 + application/libs/tasks/task.py | 24 ++++++++++++++++++------ 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/application/config/config.yaml b/application/config/config.yaml index 09a9fb7..5236896 100644 --- a/application/config/config.yaml +++ b/application/config/config.yaml @@ -33,7 +33,7 @@ Logger: Retention: Scheduler: - Start: 2023-11-12 10:04:00 + Start: 2023-11-12 12:08:00 End: 2099-11-11 16:00:00 Timezone: Asia/Shanghai diff --git a/application/libs/helper/__init__.py b/application/libs/helper/__init__.py index c304e7b..dfea5b4 100644 --- a/application/libs/helper/__init__.py +++ b/application/libs/helper/__init__.py @@ -13,3 +13,4 @@ from .config import ConfigHelper from .env import EnvVarHelper from .file import FileHelper +from .mysql import MySQLHelper diff --git a/application/libs/tasks/task.py b/application/libs/tasks/task.py index 58f3894..14925c5 100644 --- a/application/libs/tasks/task.py +++ b/application/libs/tasks/task.py @@ -14,6 +14,7 @@ import datetime from application.extensions.init_sqlalchemy import db from application.models import User from application.common import global_config +from application.libs.helper import MySQLHelper def task(): @@ -23,9 +24,20 @@ def task(): :return: None """ with db.app.app_context(): - print("create user") - user = User(username="CWzz", email="Stuu@outlook.com", password="qwe!2345", active=True, - created_at=datetime.datetime.utcnow()) - user.save() - print(db.app.config) - print("created user admin") + cfg = db.app.config.ExtraDB + options = { + "host": cfg.Host, + "user": cfg.User, + "password": cfg.Password, + "database": cfg.DB, + "port": cfg.Port, + } + with MySQLHelper(**options) as helper: + print(helper.execute(cfg.Sql)) + print("create user") + # user = User(username="CWzz", email="Stuu@outlook.com", password="qwe!2345", active=True, + # created_at=datetime.datetime.utcnow()) + # user.save() + print(db.app.config) + + print("created user admin") -- GitLab