Guest User

Untitled

a guest
Jan 10th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | None | 0 0
  1. import datetime
  2. import java.io
  3. import json
  4. from java.nio.charset import StandardCharsets
  5. from org.apache.nifi.processor.io import StreamCallback
  6. from org.apache.commons.io import IOUtils
  7.  
  8.  
  9. class PyStreamCallback(StreamCallback):
  10.     def __init__(self):
  11.         pass
  12.     def process(self, inputStream, outputStream):
  13.         fcontent = IOUtils.toString(inputStream, StandardCharsets.UTF_8)
  14.         j = json.loads(fcontent)
  15.         t = datetime.datetime.strptime(j['CollectionDate'], '%d.%m.%Y %H:%M:%S').strftime('%Y-%m-%dT%H:%M:%SZ')
  16.         j['MetaInfo'] = [ {'CollectionDate': t }]
  17.         snd = json.dumps(j, sort_keys=True, ensure_ascii=False, indent=4)
  18.         outputStream.write(snd.encode('utf-8'))
  19.  
  20.  
  21. flist = session.get(10)
  22. for f in flist:
  23.     try:
  24.         if (f != None):
  25.             f = session.write(f, PyStreamCallback())    
  26.             session.transfer(f, REL_SUCCESS)
  27.     except Exception:
  28.         session.transfer(f, REL_FAILURE)
Advertisement
Add Comment
Please, Sign In to add comment