Guest User

Untitled

a guest
Dec 28th, 2018
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. #-*- coding: utf-8 -*-
  3. import pymysql.cursors
  4. import pandas
  5. from sendmail_file import sendmail
  6.  
  7. ###conf
  8. #Export to filename
  9. filename = 'info.xls'
  10.  
  11. #Email set config
  12. smtp_host = 'smtp.yandex.ru'
  13. smtp_port = '465'
  14. fromaddr = ''
  15. toaddr = ''
  16. upass = ''
  17.  
  18. #Msg
  19. subject = filename
  20. body = 'TEXT'
  21.  
  22. db = pymysql.connect(host='localhost', user='xls', passwd='', db='xls', charset='utf8')
  23.  
  24. sql = 'SELECT * FROM `TABLE 1` limit 10'
  25.  
  26. cursor = db.cursor()
  27. cursor.execute(sql)
  28. data = cursor.fetchone()
  29.  
  30. df = pandas.read_sql(sql, db)
  31.  
  32. #Export to csv
  33. #df.to_csv('info.csv', index=False)
  34.  
  35. #Export to xls
  36. df.to_excel(filename, index=False)
  37.  
  38. db.close()
  39.  
  40. print("Done Export to xls file")
  41.  
  42. # File to sendmail
  43.  
  44. if data == None:
  45. print("table is empty")
  46. else:
  47. sendmail(fromaddr, upass, toaddr, subject, body, filename, smtp_host, smtp_port)
  48. print("file to send mail")
Add Comment
Please, Sign In to add comment