diff --git a/bin/SQLDataCreating.py b/bin/SQLDataCreating.py new file mode 100644 index 0000000..843bebe --- /dev/null +++ b/bin/SQLDataCreating.py @@ -0,0 +1,61 @@ +# -*- coding:utf-8 -*- +import _load + +import faker_data +import yaml +import codecs + +import jaydebeapi +from schedule import every, repeat, run_pending +from pathlib import Path +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"] + +OAuth = [str(db_user),str(db_password)] +if not db_user and not db_password: + OAuth = None +#conn to db by jaydebeapi +conn = jaydebeapi.connect(driver_name, + jdbc_url, + OAuth, + driver_jar_path) + + + + + + +@repeat(every(2).seconds) +def create_table(): + print("create_table ....") + + +@repeat(every(20).seconds) +def insert_data(): + print("insert_data ....") + + +@repeat(every(5).seconds) +def dalete_data(): + print("dalete_data....") + + +@repeat(every(6).seconds) +def updata_data(): + print("updata_data ....") + + + +if __name__ == '__main__': + while True: + run_pending() diff --git a/bin/fileDataCreating.py b/bin/fileDataCreating.py index a17513c..0ae6e4d 100644 --- a/bin/fileDataCreating.py +++ b/bin/fileDataCreating.py @@ -18,6 +18,7 @@ from random import choice 5. 每10分钟,从当天的文件中随机找个1个文件,删除前100条数据 6. 每6小时,从所有的文件中随机删除1个文件 """ +#TODO(MH):目前这些参数是写死的,后续看使用情况,也可以去读配置文件的 # 定义公共的部分 @@ -29,8 +30,6 @@ if not data_dir.exists(): data_dir.mkdir() # 定义文件的信息 - - def file_info(): file_info_list = [] now = datetime.now() @@ -49,9 +48,7 @@ def file_info(): return (file_info_list) # 每小时生成一个10M大小的csv文件 -# @repeat(every(1).hours) --是基于运行的时间,不是基于系统时间 - - +# @repeat(every(1).hours) TODO(MH):这个是基于运行的时间,不是基于系统时间 def new(): print('new...') # 创建文件夹 diff --git a/etc/driver/mysql-connector-java-8.0.29.jar b/etc/driver/mysql-connector-java-8.0.29.jar new file mode 100644 index 0000000..5f9f134 Binary files /dev/null and b/etc/driver/mysql-connector-java-8.0.29.jar differ diff --git a/etc/test_config.yml b/etc/test_config.yml new file mode 100644 index 0000000..be06d4f --- /dev/null +++ b/etc/test_config.yml @@ -0,0 +1,7 @@ +#数据库配置文件 +driver_name: "com.mysql.cj.jdbc.Driver" +driver_jar: "mysql-connector-java-8.0.29.jar" + +jdbc_url: "jdbc:mysql://10.10.29.9:3306/" +db_user: "root" +db_password: "Unary@2023" diff --git a/requirements.txt b/requirements.txt index c735ed6..6e3f8bd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ faker==19.12.0 schedule==1.2.1 +PyYAML==6.0.1