python在windows上调用 kettle
原理是python调用cmd
cmd = 'kitchen.bat -rep=kettle_repo -user=admin -pass=admin -dir=/job -job=material_inventory "-param:t_date=\'2018-01-01\'" -level=Error'
os.system(cmd)
rep为资源库
dir为目录
job为任务名
param为参数
由于这个job每次只能跑一天的数据,一次次的输参数很麻烦,所以这里用python写个时间循环,来调用kettle.
整体代码如下
import os, datetime
import pandas as pd
start = '2018-11-01'
end = (datetime.datetime.now()-datetime.timedelta(days=1)).strftime('%Y-%m-%d')
date_start = datetime.datetime.strptime(start, '%Y-%m-%d')
date_end = datetime.datetime.strptime(end, '%Y-%m-%d')
for i in pd.date_range(datestart, dateend):
cmd = 'kitchen.bat -rep=yao -user=admin -pass=admin -dir=/job -job=material_inventory "-param:t_date=\'%s\'" -level=Error' % (i)
os.system(cmd)