Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- #-*- coding: utf-8 -*-
- import pymysql.cursors
- import pandas
- from sendmail_file import sendmail
- ###conf
- #Export to filename
- filename = 'info.xls'
- #Email set config
- smtp_host = 'smtp.yandex.ru'
- smtp_port = '465'
- fromaddr = ''
- toaddr = ''
- upass = ''
- #Msg
- subject = filename
- body = 'TEXT'
- db = pymysql.connect(host='localhost', user='xls', passwd='', db='xls', charset='utf8')
- sql = 'SELECT * FROM `TABLE 1` limit 10'
- cursor = db.cursor()
- cursor.execute(sql)
- data = cursor.fetchone()
- df = pandas.read_sql(sql, db)
- #Export to csv
- #df.to_csv('info.csv', index=False)
- #Export to xls
- df.to_excel(filename, index=False)
- db.close()
- print("Done Export to xls file")
- # File to sendmail
- if data == None:
- print("table is empty")
- else:
- sendmail(fromaddr, upass, toaddr, subject, body, filename, smtp_host, smtp_port)
- print("file to send mail")
Add Comment
Please, Sign In to add comment