HandleFile.py
1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# @Time : 2022/8/24 16:07
# @Author : 付孟奇
from config.VendorPath import global_path
from util.HandleLog import logger
import configparser
import json
import base64
import yaml
# 读取ini文件内容
def load_ini_file(file_path, sec):
logger.info("{} 文件加载中......".format(file_path))
config = configparser.ConfigParser()
config.read(file_path, encoding="UTF-8")
data = dict(config[sec])
logger.info("{} 文件加载成功......".format(file_path))
return data
# 读取yaml文件内容
def load_yaml_file(file_path):
logger.info("{} 文件加载中......".format(file_path))
with open(file_path, encoding='utf-8') as f:
data = yaml.safe_load(f)
logger.info("{} 文件加载成功......".format(file_path))
return data
# 读取json文件并重新存储
def file_read_save(file_path, file_key, file_value):
with open(file_path, 'r+') as f:
file_data = json.load(f)
file_data[str(file_key)] = file_value
f.seek(0)
f.truncate()
json.dump(file_data, f, indent=4, ensure_ascii=False)
logger.info('响应信息存储完毕!!!')
# 读取公共参数文件指定内容
def file_read_global(args):
with open(global_path, 'r') as f:
file_data = json.load(f)
res = file_data[args[0]][args[1]]
return res
# 读取图片转换64
def file_base_64(path):
with open(path, 'rb') as f:
base64_data = base64.b64encode(f.read())
data = base64_data.decode()
return data