File tree Expand file tree Collapse file tree 1 file changed +28
-3
lines changed
Expand file tree Collapse file tree 1 file changed +28
-3
lines changed Original file line number Diff line number Diff 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
4873if __name__ == '__main__' :
49- test ()
74+ test_bulk ()
You can’t perform that action at this time.
0 commit comments