'How schedule sql query by Python?

I have sql query and I want to run automatically daily at 9:30 am. I don't have permission to use SQL Server Agent so I try to workaround and use Python.

SQLQuery1.sql looks like:

with tab1 as (select....),
tab2 as (select ...)

select ...
into newtab
from tab1
left join tab2...

In Python works:

import pyodbc

con = pyodbc.connect(driver=...)
cur = con.cursor()
sql_file = open("SQLQuery1.sql")
sql_as_string = sql_file.read()
res = cur.execute(sql_as_string)
#con.commit()
print("Success!")

I find some information about schedule: https://schedule.readthedocs.io/en/stable/ but I don't know what I should write after def job() and where I should save this code:

import schedule
import time

def job():
    #?????

schedule.every().day.at("09:30").do(job)

while True:
    schedule.run_pending()
    time.sleep(1)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source