I want to send mail every 2nd Friday in month at 4:00 p.m. How we will do in python. I know following logic is not efficient, is there other way to do this in python?
// Pseudocode for check 2nd Friday and time 4:00 p.m.
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
}
}
Double-click on the Task Scheduler, and then choose the option to 'Create Basic Task…' Type a name for your task (you can also type a description if needed), and then press Next. For instance, let's name the task as: Run Hello World. Choose to start the task 'Daily' since we wish to run the Python script daily at 6am.
To schedule a Python script with Task scheduler, create an action and add the path to your Python executable file, add the path to the script in the “Start in” box and add the name of the Python file ase an argument. Then, create a trigger to schedule the execution of your script.
Sending emails manually is a time-consuming and error-prone task, but it's easy to automate with Python. In this tutorial you'll learn how to: Set up a secure connection using SMTP_SSL() and .
You can use the python-crontab
module.
https://pypi.python.org/pypi/python-crontab
Here's how you can use it:
from crontab import CronTab
#Initialize Cron
cron = CronTab()
#Add your jobs
job = cron.new(command='/usr/bin/echo')
#Set period
job.hour.every(4)
Alternatively, you can use crontab -e
and follow this link: http://adminschoice.com/crontab-quick-reference
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With