I have below python script dbreport.py where I am using cx_Oracle module to connect the oracle db and it is working fine.Now I have some sql statements which I want to run and generate the output of that into html report.Mentioning some part of the python script.The issue here is I want to add the below sql to generate the output in html format in below python script function.I am not sure how to achieve this.
######Sql statement to generate html report#######
SET MARKUP HTML ON SPOOL ON PREFORMAT OFF ENTMAP ON -
HEAD "<TITLE>EMPLOYEE REPORT</TITLE> -
<STYLE type='text/css'> -
<!-- BODY {background: #FFFFC6} --> -
</STYLE>" -
BODY "TEXT='#FF00Ff'" -
TABLE "WIDTH='90%' BORDER='5'"
spool report2.html
Select * from hr.departments where date = '{}'.format(dt_string)
spool off
#######dbreport.py script##########################
import cx_Oracle
def main(env_name):
try:
now datetime.now()
dt_string = now.strftime("%Y%m%d")
connection = Connection("ABC_DEV_KK","username", "pass")
cursor = connection.cursor()
cursor.execute()---------------------I tried here but not succesfull
res = cursor.fetchall()
print(res)
except Exception as e:
logging.info(e)
if _name_ == '_main_':
main()