import json
# 目标文件
cta_hla_filename = "cta_strategy_data_2503023_hla.json"
cta_hsr_filename = "cta_strategy_data_2503023_hsr.json"
# 写入文件
cta_target_filename = "sum_test.json"
def tqz_load_jsonfile(filename=""):
if "" == filename:
exception = Exception("Error: filename is empty")
raise exception
else:
with open(cta_hla_filename, "r", encoding="utf-8") as fp:
return json.load(fp=fp)
def tqz_write_jsonfile(content="", filename=""):
if "" == filename:
exception = Exception("Error: filename is empty")
raise exception
else:
# content_json = json.dumps(obj=content, ensure_ascii=False) # content_json: string 类型, 目前需要字典类型
with open(filename, "w", encoding="utf-8") as fp:
json.dump(content, fp=fp, ensure_ascii=False)
# 读取json文件数据
cta_hla_dic = tqz_load_jsonfile(filename=cta_hla_filename)
cta_hsr_dic = tqz_load_jsonfile(filename=cta_hsr_filename)
new_dic = {}
for (key, value) in cta_hsr_dic.items():
value["pos"] = cta_hla_dic[key]["pos"] + cta_hsr_dic[key]["pos"]
new_dic[key] = value
tqz_write_jsonfile(new_dic, cta_target_filename)