Richard
Richard

Reputation: 15862

how to make a script be active for only on every hour on the half hour?

I have a script and I want to code it so that it becomes active every hour on the half hour. This is the code I have so far.

from ConfigParser import *
import emailModule
from datetime import datetime
import time

configuration = ConfigParser()
configuration.read('Email.conf')

email = emailModule.emailModule(configuration)



while(True):


    if (datetime.now().minute > 28 and datetime.now().minute < 32):

        email.emailWeather()
        time.sleep(3000)

I am just wondering is there a better way of doing this in python? IE a more efficient way or more reliable way of doing things.

Upvotes: 0

Views: 291

Answers (2)

Blue Peppers
Blue Peppers

Reputation: 3808

If you are using linux, or any other system with a cronlike daemon, you could ask the system to run your script every hour on the half hour by putting a line like this in your crontab: 30 * * * * /path/to/script

Upvotes: 2

Manjoor
Manjoor

Reputation: 4199

You can use cron jobs. Schedule it for every 1 hr. starting at 00:30:00.

Upvotes: 2

Related Questions