gee*_*eks 6 python scheduled-tasks
我希望每个月的第二个星期五下午4点发送邮件.我们将如何在python中进行.我知道以下逻辑效率不高,有没有其他方法可以在 python中执行此操作?
//第二个星期五和下午4:00的伪代码
function(Day='Fri',Time='4:00 p.m.')
while(1){
String current_date=new date();// This will in following formate.
// Fri Aug 21 2015 16:00:00 GMT+0530 (IST).
// Here we can see that it is combination of Date, Day and time.
//Now this is the current_date is string so search the sub string 'Fri'
if(current_date.substring('Fri') && current_date.substring('16:00:00')){
// Now search for this date is 2nd Friday or not,
int day=current_date.getDay();
if(day>7 && day<=13)
start_script to send mail
}
}
Run Code Online (Sandbox Code Playgroud)
您可以使用 Celery 定期任务来自动执行此操作。看看这里http://celery.readthedocs.org/en/latest/userguide/periodic-tasks.html
Celery 将代表您处理 cron,并为您提供许多附加工具,例如登录和界面,这些工具应该使您的脚本可扩展(对于更多用户、任务等)
| 归档时间: |
|
| 查看次数: |
6651 次 |
| 最近记录: |