Jelajahi Sumber

MOD:修改config获取数据库配置方式

cxyu 3 tahun lalu
induk
melakukan
97408476cf
2 mengubah file dengan 21 tambahan dan 14 penghapusan
  1. 7 1
      config/db_config.yaml
  2. 14 13
      model/DataBaseUtils.py

+ 7 - 1
config/db_config.yaml

@@ -27,4 +27,10 @@ zx_test:
   host: 118.178.187.109
   user: root
   passwd: zxdev3306
-  db: zx-operation-test
+  db: zx-operation-test
+
+clickhouse:
+  host: cc-bp1h3yc7o3g3o7k64o.ads.aliyuncs.com
+  user: qucheng_ck
+  passwd: Qc123456
+  port: 3306

+ 14 - 13
model/DataBaseUtils.py

@@ -9,10 +9,16 @@ import yaml
 import os
 import pandas as pd
 from clickhouse_driver.client import Client
-import json
 log = logger()
 
 
+def db_config():
+    p_path = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
+    path = os.path.join(p_path, "config", "db_config.yaml")
+    f = open(path, encoding="utf-8")
+    config = yaml.load(f.read(), Loader=yaml.FullLoader)
+    return config
+
 class MysqlUtils:
     _quchen_text = None
     _zx=None
@@ -21,14 +27,7 @@ class MysqlUtils:
     _zx_test =None
 
     def __init__(self):
-        p_path =os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
-        path = os.path.join(p_path,"config", "db_config.yaml")
-        f = open(path, encoding="utf-8")
-        self.config = yaml.load(f.read(), Loader=yaml.FullLoader)
-
-
-
-
+        self.config = db_config()
 
     @property
     def quchen_text(self):
@@ -111,10 +110,12 @@ class MysqlUtils:
 class CkUtils:
 
     def __init__(self):
-        self.client = Client(host='cc-bp1h3yc7o3g3o7k64o.ads.aliyuncs.com',
-                           user='qucheng_ck',
-                           password='Qc123456',
-                           port='3306',
+        self.config=db_config()
+        conf = self.config['clickhouse']
+        self.client = Client(host=conf['host'],
+                           user=conf['user'],
+                           password=conf['passwd'],
+                           port=conf['port'],
                            send_receive_timeout=5)
 
     def execute(self, sql):