How to trigger a python script run certain time automatically?

I am new to Python. I have a “” script which is schedule by zcron to run every 2 hrs. But currently the automatic refresh is having issue.

I used schedule libraries but still unable to achieve my results.please suggest.

I tried this code in the python script like below code where I import CronJob

import schedule
import time
import datetime as dt
import os
import psutil

log_output_file = 'C:\\Python Scripts\\Production\\Python Scripts\\log.txt'
path_scripts = 'C:\\Python Scripts\\Production\\Python Scripts\\'

def log_file(message, log_output_file, file_attribute):
    f = open(log_output_file, file_attribute)

now =
print ("Current date and time : ")
print (now.strftime("%d-%m-%Y %H:%M:%S"))
log_file(now.strftime("%d-%m-%Y %H:%M:%S"), log_output_file, 'w')

# delete any excel workbooks that were opened during a reboot
# system account files
dir='C:\\Program Files\\Microsoft Office\\root\\Office16\\XLSTART'
for root, dirs, files in os.walk(dir):
    for name in files:

        os.remove(os.path.join(root, name))

# remove any instances of excel still running
for proc in psutil.process_iter():
    if == "EXCEL.EXE":

def get_time() -> str:
    r'''Get current time and date and return as string.'''
    return time.strftime('%X (%d/%m/%y)')
def myjob():
    print("I’m working...",get_time())
    log_file('\n', log_output_file, 'a')
    log_file('CronJob', log_output_file, 'a')
    exec(open(path_scripts + '').read())

now =
print ("Current date and time : ")
print (now.strftime("%d-%m-%Y %H:%M:%S"))
log_file('\n', log_output_file, 'a')
log_file(now.strftime("%d-%m-%Y %H:%M:%S"), log_output_file, 'a')

while True:

The above code is running with some error.

Current date and time :
24-04-2024 15:21:36
Current date and time :
24-04-2024 15:21:36
I’m working... 15:25:36 (24/04/24)
Obtain auth cookie
Obtain X-RequestDigest
Connect to SharePoint
Connect to SQLite Database
Create instance of Excel
Open Excel Template
Turn off calculations
Turn off alerts
Get License Data
Turn on calculations
Refresh workbook
Save Workbook
Upload file to SharePoint
Close out
Traceback (most recent call last):
  File "c:\Python Scripts\Production\Python Scripts\", line 53, in <module>
  File "C:\Python\Lib\site-packages\schedule\", line 822, in run_pending
  File "C:\Python\Lib\site-packages\schedule\", line 100, in run_pending
  File "C:\Python\Lib\site-packages\schedule\", line 172, in _run_job
    ret =
  File "C:\Python\Lib\site-packages\schedule\", line 693, in run
    ret = self.job_func()
  File "c:\Python Scripts\Production\Python Scripts\", line 42, in myjob
    exec(open(path_scripts + '').read())
  File "<string>", line 268, in <module>
  File "<string>", line 46, in close_out
NameError: name 'sqlite_connection' is not defined

Is it possible that gets trigger itself to run other python codes ?