提交代码

This commit is contained in:
halliday 2023-10-25 21:47:36 +08:00
parent f10f61392d
commit 02b0bd7eb0
3 changed files with 38 additions and 20 deletions

View File

@ -13,31 +13,49 @@ from datetime import datetime
# 定义公共的部分
path = Path(__file__)
configfile = path.parent.parent / "etc/test_config.yml"
db_config = yaml.load(codecs.open(configfile ,'r',encoding='utf-8'),Loader=yaml.FullLoader)
driver_name = db_config["driver_name"]
driver_jar_path = db_config["driver_jar_path"]
db_user = db_config["db_user"]
db_password = db_config["db_password"]
jdbc_url = db_config["jdbc_url"]
etc_dir = path.parent.parent / "etc"
configfile = etc_dir / "test_config.yml"
db_config = yaml.load(codecs.open(
configfile, 'r', encoding='utf-8'), Loader=yaml.FullLoader)
driver_jar_path = etc_dir / "driver" / db_config["driver_jar"]
OAuth = [str(db_user),str(db_password)]
if not db_user and not db_password:
OAuth = [str(db_config["db_user"]), str(db_config["db_password"])]
if not db_config["db_user"] and not db_config["db_password"]:
OAuth = None
#conn to db by jaydebeapi
conn = jaydebeapi.connect(driver_name,
jdbc_url,
# conn to db by jaydebeapi
conn = jaydebeapi.connect(db_config["driver_name"],
db_config["jdbc_url"],
OAuth,
driver_jar_path)
str(driver_jar_path))
# conn.close()
def execute_sql(sql):
with conn.cursor() as curs:
curs.execute(sql)
# selecet_sql = "select * from t22 t WHERE name like '李%'"
# execute_sql(selecet_sql)
@repeat(every(2).seconds)
#@repeat(every(1).hours)
def create_table():
print("create_table ....")
sql_string = "CREATE TABLE `"
sql_string += "test"
sql_string += "` ("
sql_string += "`uuid` varchar(50) DEFAULT NULL,"
sql_string += "`id` bigint DEFAULT NULL,"
sql_string += "`name` varchar(50) DEFAULT NULL,"
sql_string += "`mobile` varchar(50) DEFAULT NULL,"
sql_string += "`ssn` varchar(50) DEFAULT NULL,"
sql_string += "`sex` int DEFAULT NULL,"
sql_string += "`email` varchar(50) DEFAULT NULL,"
sql_string += "`job` varchar(50) DEFAULT NULL,"
sql_string += "`address` varchar(50) DEFAULT NULL,"
sql_string += "`actime_time` timestamp NULL DEFAULT NULL"
sql_string += ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;"
execute_sql(sql_string)
@repeat(every(20).seconds)
@ -55,7 +73,6 @@ def updata_data():
print("updata_data ....")
if __name__ == '__main__':
while True:
run_pending()

View File

@ -1,7 +1,7 @@
#数据库配置文件
driver_name: "com.mysql.cj.jdbc.Driver"
driver_name: "com.mysql.jdbc.Driver"
driver_jar: "mysql-connector-java-8.0.29.jar"
jdbc_url: "jdbc:mysql://10.10.29.9:3306/"
jdbc_url: "jdbc:mysql://10.10.29.9:3306/test2"
db_user: "root"
db_password: "Unary@2023"

View File

@ -1,4 +1,5 @@
faker==19.12.0
schedule==1.2.1
PyYAML==6.0.1
JayDeBeApi==1.2.3