Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import datetime
- import java.io
- import json
- from java.nio.charset import StandardCharsets
- from org.apache.nifi.processor.io import StreamCallback
- from org.apache.commons.io import IOUtils
- class PyStreamCallback(StreamCallback):
- def __init__(self):
- pass
- def process(self, inputStream, outputStream):
- fcontent = IOUtils.toString(inputStream, StandardCharsets.UTF_8)
- j = json.loads(fcontent)
- t = datetime.datetime.strptime(j['CollectionDate'], '%d.%m.%Y %H:%M:%S').strftime('%Y-%m-%dT%H:%M:%SZ')
- j['MetaInfo'] = [ {'CollectionDate': t }]
- snd = json.dumps(j, sort_keys=True, ensure_ascii=False, indent=4)
- outputStream.write(snd.encode('utf-8'))
- flist = session.get(10)
- for f in flist:
- try:
- if (f != None):
- f = session.write(f, PyStreamCallback())
- session.transfer(f, REL_SUCCESS)
- except Exception:
- session.transfer(f, REL_FAILURE)
Advertisement
Add Comment
Please, Sign In to add comment