在add_job
中添加参数day_of_week
即可:
from datetime import datetime
from apscheduler.schedulers.background import BlockingScheduler
def auto_run():
print("运行程序")
print(datetime.now())
def main():
print("测试周N自动运行")
scheduler = BlockingScheduler(timezone='Asia/Shanghai')
scheduler.add_job(auto_run, 'cron', hour=10, minute=26, day_of_week='0', misfire_grace_time=60 * 60,
max_instances=3) # 0 表示周一
scheduler.start()
if __name__ == '__main__':
main()
最后效果: