如何使用星期几(周二)来代替日期(5-12-2000),在特定的时间执行程序?

问题描述 投票:0回答:1
from datetime import date
from apscheduler.scheduler import Scheduler

 # Start the scheduler
 sched = Scheduler()
 sched.start()

 # Define the function that is to be executed
 def my_job(text):
     print text

 # The job will be executed on November 6th, 2009
 exec_date = date(2009, 11, 6)

 # Store the job in a variable in case we want to cancel it
 job = sched.add_date_job(my_job, exec_date, ['text'])
python datetime python-3.6 apscheduler
1个回答
1
投票

你可以使用cron风格的调度来添加一周中某一天的工作。

你的 add_date_job 可以写成 。

sched.add_cron_job(my_job, args = ['text'], day_of_week='tue')

提醒一下,一定要给你的工作添加具体的时间,否则调度器会把默认的时、分、秒作为*,每秒钟都会触发。

apscheduler的参考资料。https:/apscheduler.readthedocs.ioenstableindex.html。

© www.soinside.com 2019 - 2024. All rights reserved.