You can download this code by clicking the button below.
This code is now available for download.
This code defines a function named 'daily_task' that runs at 9 AM every day. It uses the Schedule library to set up timed tasks and runs the scheduler in an infinite loop.
Technology Stack : Schedule, datetime
Code Type : Timed task
Code Difficulty : Intermediate
import schedule
import datetime
def daily_task():
now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
print(f"Task executed at: {now}")
# Schedule the task to run every day at 9 AM
schedule.every().day.at("09:00").do(daily_task)
# Run the scheduler in an infinite loop
while True:
schedule.run_pending()
time.sleep(1)