# 更新clickhouse的默认配置 并保存信息
import configparser
import os
from com.fl.dev.util.StringUtil import verifyIp
def set_clickhouse_conn(ck_host, ck_port, ck_username, ck_password):
"""
获取股票tick数据
Parameters
--------
ck_host:string
clickhouse的服务器ip
ck_port : string
clickhouse的端口号
ck_usrname : string
clickhouse的用户名
ck_password : string
clickhouse的密码
"""
base_dir = str(os.path.dirname(os.path.dirname(__file__)))
base_dir = base_dir.replace('\\', '/')
file_path = base_dir + "/io/config.ini"
conf = configparser.ConfigParser()
conf.read(file_path)
if (verifyIp(ck_host)):
conf.set('clickhouse_db', 'ck_host', ck_host)
else:
raise AssertionError('IP invaild', ck_host)
if ck_port:
conf.set('clickhouse_db', 'ck_port', ck_port)
else:
raise AssertionError('IP invaild', ck_port)
if ck_username:
conf.set('clickhouse_db', 'ck_username', ck_username)
else:
raise AssertionError('username can not be blank!', ck_username)
if ck_password:
conf.set('clickhouse_db', 'ck_password', ck_password)
else:
raise AssertionError('password can not be blank!', ck_password)
with open(file_path, 'w')as config:
conf.write(config)
return 'set clickhouse info success'
if __name__ == '__main__':
res = set_clickhouse_conn('12.22.22.21', '8123', 'default', '123456')
print(res)