本文共 1183 字,大约阅读时间需要 3 分钟。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | 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() |