Skip to content

Instantly share code, notes, and snippets.

@ssummer3
Forked from ijokarumawak/read-flowfile-contents.py
Last active February 1, 2017 13:14
Show Gist options
  • Save ssummer3/311bc5b281efdbdbe14f2b29a03fa509 to your computer and use it in GitHub Desktop.
Save ssummer3/311bc5b281efdbdbe14f2b29a03fa509 to your computer and use it in GitHub Desktop.
Example Python script to use from NiFi ExecuteScript processor which reads the first line from an incoming flow file.
from org.python.core.util.FileUtil import wrap
from org.apache.nifi.processors.script import ExecuteScript
first_line = None
flow_file = session.get()
def read_first_line(input):
global first_line
with wrap(input) as f:
first_line = f.readline()
if flow_file:
session.read(flow_file, read_first_line)
if first_line:
flow_file = session.putAttribute(flow_file, 'from-content', first_line)
session.transfer(flow_file, ExecuteScript.REL_SUCCESS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment