我正在尝试在 python 中构建一个 cron 作业调度程序,它从数据库中获取一个时间表并使用 crontab 库在 linux 中创建 cron 作业。但我无法弄清楚如何在尝试添加星期几时克服“无法识别的星期几:”错误,我希望 cron 在从数组中指定时运行。关于如何使用数组执行此操作的任何帮助都会非常有帮助。from crontab import CronTabfrom datetime import datetimecron=CronTab('pi')#the below line simulates grabbing the data from the databaserow={'starttime':'2:56:00','sun':1,'mon':1,'tue':0,'wed':0,'thu':1,'fri':0,'sat':1}#convert the "starttime" into the hour and minute to use on the crond=datetime.strptime(row['starttime'],'%H:%M:%S')hour=d.strftime('%H')minute=d.strftime('%M')#figure out what day of week I want the cron to run ondow=[]if(row['sun'] == 1): dow.append("Sun") if(row['mon'] == 1): dow.append("Mon") if(row['tue'] == 1): dow.append("Tue")if(row['wed'] == 1): dow.append("Wed")if(row['thu'] == 1): dow.append("Thu")if(row['fri'] == 1): dow.append("Fri")if(row['sat'] == 1): dow.append("Sat")#create the jobjob=cron.new(command='python /home/pi/Documents/blinktest.py', comment='Schedule')job.minute.on(minute)job.hour.on(hour)job.dow.on(dow) #<- this is the line I get the "unrecognised day of week" error#write the croncron.write()这是我得到的错误:ValueError: Unrecognised Day of Week: '['Sun', 'Mon', 'Thu', 'Sat']'
添加回答
举报
0/150
提交
取消