-
Notifications
You must be signed in to change notification settings - Fork 0
/
WenAnDiff1.py
142 lines (119 loc) · 3.76 KB
/
WenAnDiff1.py
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
"""
=== Excel操作 ===
=== CaseData: 保存数据类 ===
=== ExcelHandle: 处理Excel文件 ===
"""
import os
import openpyxl, json
class CaseData(object):
pass
class ExcelHandle(object):
"""处理Excel文件"""
def __init__(self, file_name, sheet_name):
self.file_name = file_name
self.sheet_name = sheet_name
def __open(self):
self.wb = openpyxl.load_workbook(self.file_name)
self.sh = self.wb[self.sheet_name]
def get_data_dict(self, num) -> dict:
"""读取数据存储在字典中"""
self.__open()
rows = list(self.sh.rows)
return [dict(zip([i.value for i in rows[0]], [r.value for r in row]))
for row in rows[1:num]]
def get_data_obj(self) -> list:
"""读取数据存储在类中"""
self.__open()
rows = list(self.sh.rows)
# 定义用例列表,用来存放用例类列表
cases = []
# 遍历用例数据行
for row in rows[1:]:
# 把每一行的数据通过zip进行打包,然后转成字典,存入到用例数据列表中
case = dict(zip([i.value for i in rows[0]], [r.value for r in row]))
# 定义一个用例存放类对象
case_obj = CaseData()
for k, v in case.items():
# 通过setattr()给对象添加属性
setattr(case_obj, k, v)
# 把对象添加到列表中
cases.append(case_obj)
return cases
if __name__ == '__main__':
file = "/Users/liqi/Desktop/文档/产品文档.xlsx"
eh = ExcelHandle(file, "仅V4")
data = eh.get_data_dict(665) # list类型
# print(data)
with open("/Users/liqi/Documents/tronlink-extension-pro/src/i18n/en.json", 'r') as f:
load_dict_en = json.load(f)
# print(load_dict_en)
with open("/Users/liqi/Documents/tronlink-extension-pro/src/i18n/ja.json", 'r') as f:
load_dict_ja = json.load(f)
# print(load_dict_ja)
with open("/Users/liqi/Documents/tronlink-extension-pro/src/i18n/zh_CN.json", 'r') as f:
load_dict_zh = json.load(f)
# print(load_dict_zh)
list = list(load_dict_zh.keys())
# print(list)
dict_zh = {}
dict_en = {}
dict_jp = {}
for dict in data:
# 遍历excel中的key,写三个dict(中,英,日)
dict_zh[dict['key']] = dict['zh']
dict_en[dict['key']] = dict['en']
dict_jp[dict['key']] = dict['jp']
print('对比中文文案结果:')
print(load_dict_zh == dict_zh)
diff_key = load_dict_zh.keys() ^ dict_zh.keys()
# print(diff_key)
list_result_zn = []
for i in diff_key:
list1 = []
list1.append(i)
if i in load_dict_zh.keys():
list1.append(load_dict_zh[i])
else:
list1.append("空")
if i in dict_zh.keys():
list1.append(dict_zh[i])
else:
list1.append("空")
list_result_zn.append(list1)
print(list_result_zn)
print('对比英文文案结果:')
print(load_dict_en == dict_en)
diff_key = load_dict_en.keys() ^ dict_en.keys()
# print(diff_key)
list_result_en = []
for i in diff_key:
list1 = []
list1.append(i)
if i in load_dict_en.keys():
list1.append(load_dict_en[i])
else:
list1.append("空")
if i in dict_zh.keys():
list1.append(dict_en[i])
else:
list1.append("空")
list_result_en.append(list1)
print(list_result_en)
print('对比日文文案结果:')
print(load_dict_ja == dict_jp)
diff_key = load_dict_ja.keys() ^ dict_jp.keys()
# print(diff_key)
list_result_ja = []
for i in diff_key:
list1 = []
list1.append(i)
if i in load_dict_ja.keys():
list1.append(load_dict_ja[i])
else:
list1.append("空")
if i in dict_jp.keys():
list1.append(dict_jp[i])
else:
list1.append("空")
list_result_ja.append(list1)
print(list_result_ja)