Is there a way that I can make a python command get sent at exactly midnight?

Viewed 513

I am trying to make a booking script that will book an event at exactly midnight. I have writen all the code and it all works I just need to activate the book command at exactly midnight. Many Thanks if you can help me out

1 Answers

You can either:

Use the schedule module

Start with installing it from pip with: pip install schedule
And then you can use that module like that:

import schedule

def foo():
    print("Fooing around")

schedule.every().day.at("00:00").do(foo)

Use cron job (On Linux and macOS)

Use the command: crontab -e to edit the cron jobs.
Add the following line to execute your script every midnight:

00 00 * * * python /path/to/script.py
Related