用nifi executescript 生成3小时间隔字符串

import java.io
from datetime import datetime
from org.apache.commons.io import IOUtils
from java.nio.charset import StandardCharsets
from org.apache.nifi.processor.io import StreamCallback

class GetDate(StreamCallback):
  def __init__(self):
        pass
  def process(self, inputStream, outputStream):
  	#text = IOUtils.toString(inputStream, StandardCharsets.UTF_8)
  	dt = ''
	months = [1, 4, 7, 10]
	for year in range(1990,2016):
	    for i in range(len(months)):
	        dt1 = datetime(year, months[i], 1, 0, 0, 0)
	        if months[i] == 10:
	            dt2 = datetime(year+1, 1, 1, 0, 0, 0)
	        else:
	            dt2 = datetime(year, months[i]+3, 1, 0, 0, 0)
	        dt += dt1.strftime("%Y-%m-%d %H:%M:%S") + ',' + dt2.strftime("%Y-%m-%d %H:%M:%S") + ";"
	outputStream.write(dt)
	
flowFile = session.create()
if (flowFile != None):
  flowFile = session.write(flowFile, GetDate())
  #flowFile = session.putAttribute(flowFile, "filename", flowFile.getAttribute('filename').split('.')[0]+'_translated.json')
session.transfer(flowFile, REL_SUCCESS)
session.commit()

你可能感兴趣的:(用nifi executescript 生成3小时间隔字符串)