# Import the interface required by the Script snap. from com.snaplogic.scripting.language import ScriptHook import java.util class TransformScript(ScriptHook): def __init__(self, input, output, error, log): self.input = input self.output = output self.error = error self.log = log # The "execute()" method is called once when the pipeline is started # and allowed to process its inputs or just send data to its outputs. def execute(self): self.log.info("Processing Pipeline defaults") fields={} fieldsr={} fieldn=0 while self.input.hasNext(): try: in_doc = self.input.next() KEY=in_doc['KEY'] VALUE=in_doc['VALUE'] if (KEY>' '): fieldsr.update({fieldn:KEY}) fields.update({fieldn:VALUE}) self.log.info(KEY+" = \""+VALUE+"\"") fieldn=fieldn+1 except Exception as e: errWrapper = { 'errMsg' : str(e.args) } self.log.error("Error in python script") self.error.write(errWrapper) self.log.info("DONE with Pipeline defaults") for i in range(0,fieldn): in_doc["_"+fieldsr[i]]=fields[i] self.log.info("Saving "+fieldsr[i]+" = "+fields[i]) output.write(in_doc) # The Script Snap will look for a ScriptHook object in the "hook" # variable. The snap will then call the hook's "execute" method. hook = TransformScript(input, output, error, log)