Uncategorized

How to Run a Python Script Every 5 Minutes

import time
from datetime import datetime
from csv import writer

while(True):
    try:
        list_data = []
        this_moment = datetime.today().strftime('%Y-%m-%d %H:%M:%S')
        list_data = ["price", "pName", this_moment]

        with open('CSVFILE.csv', 'a', newline='') as f_object:
            # Pass the CSV  file object to the writer() function
            writer_object = writer(f_object)
            # Result - a writer object
            # Pass the data in the list as an argument into the writerow() function
            writer_object.writerow(list_data)
            # Close the file object
            f_object.close()
        time.sleep(300)
        print(list_data)
    except:
        print("problem with script or manual exit")