jython2.7 结果文件生成

处理数据数据,变成结果文件生成在文件夹下

 1 import os
 2 import json
 3 def writeResult(path,value):
 4     path = path + r'/result.json'
 5     fp = open(path,'w')
 6     fp.write(value)
 7 try:
 8     flowFile = session.get()
 9     sharePath = flowFile.getAttribute('共享目录'.decode('utf8'))
10     filePath = flowFile.getAttribute('shpFilePath'.decode('utf8'))
11     listStr = flowFile.getAttribute('shptojsonList'.decode('utf8'))
12     f11 = sharePath+filePath
13     list = json.loads(listStr)
14     res = []
15     for x in list:
16         l = int(len(x)) - 4
17         y = filePath +'/'+ x[0:l]+".json"
18         res.append(y)
19     reStr = json.dumps(res)
20     writeResult(f11,reStr)
21     session.transfer(flowFile, REL_SUCCESS)
22 except:
23     session.transfer(flowFile, REL_FAILURE)

 

posted @ 2021-07-22 14:43  木章  阅读(59)  评论(0编辑  收藏  举报