Skip to content

Commit 175a146

Browse files
committed
新增导出json文件工具类
1 parent c93608c commit 175a146

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

tools/export.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,34 @@ def close(self):
3434
self.bulk_fp.close()
3535

3636

37-
def test():
37+
class ExportJson(object):
3838
"""
39-
测试
39+
导出json文件工具类
40+
"""
41+
def __init__(self, file_name):
42+
if file_name is None:
43+
file_name = 'json_%s.json' % time.time()
44+
file_path = os.path.dirname(file_name)
45+
if not os.path.isdir(file_path):
46+
os.mkdir(file_path)
47+
self.json_fp = open(file_name, 'a')
48+
49+
def write(self, data):
50+
"""
51+
文件写入
52+
"""
53+
self.json_fp.write(json.dumps(data).decode('raw_unicode_escape')+"\n")
54+
55+
def close(self):
56+
"""
57+
关闭文件资源
58+
"""
59+
self.json_fp.close()
60+
61+
62+
def test_bulk():
63+
"""
64+
测试ExportBulk
4065
"""
4166
export_bulk = ExportBulk('service', 'provider')
4267
test_id = '1'
@@ -46,4 +71,4 @@ def test():
4671

4772

4873
if __name__ == '__main__':
49-
test()
74+
test_bulk()

0 commit comments

Comments
 (0)