Untitled
unknown
plain_text
8 months ago
849 B
1
Indexable
Never
import datetime from apscheduler.schedulers.blocking import BlockingScheduler import os os.environ['TZ'] = 'Asia/Kolkata' # Define the function to write to the file def write_to_file(): # Define the filename with a timestamp filename = datetime.datetime.now().strftime("File_%Y-%m-%d_%H-%M-%S.txt") # Open the file for writing with open(filename, "w") as file: # Write "Hello user" and the timestamp to the file file.write("Hello user, the current time is " + str(datetime.datetime.now())) # Confirm that the file was written successfully print("File written successfully:", filename) # Create a scheduler and add the job to run every 10 minutes scheduler = BlockingScheduler() scheduler.add_job(write_to_file, 'interval', minutes=5) # Start the scheduler scheduler.start()