In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
#! / usr/bin/env python#coding:utf-8# cx_Oracle is used to access oracle and export data import cx_Oracle# xlsxwriter is used to generate xlsx files import xlsxwriterimport timeimport sys# import mail module from email.mime.text import MIMETextfrom email.mime.multipart import MIMEMultipartimport smtplib reload (sys) sys.setsys.setdefaultencodingdefaultencoding ("gbk") # modify the default code to "gbk" Solve the Chinese coding problem without setting up UnicodeDecodeError: 'ascii' codec can't decode byte 0xa1 in position 36: ordinal not in range (128) con = cx_Oracle.connect ("comm/12345678@orcl") cursor = con.cursor () # define the SQL script because the script contains text Convert it using decode ('utf-8'). Encode (' gbk') to convert sql = 'select count fee amount, locate branch center from business'''.decode (' utf-8'). Encode ('gbk') query1 = cursor.execute (sql) # execute query title = [I [0] for i in query1.description] date_now=time.strftime ("% Y%m%d" Time.localtime () # File name and its path report_name='/excel/' + "Business data" .decode ('utf-8'). Encode (' gbk') + date_now + '.xlsx' # generate xlsx format oracle query statistics report workbook = xlsxwriter.Workbook (report_name, {'constant_memory': True}) worksheet = workbook.add_worksheet () print time.ctime () data = cursor.fetchall () print time.ctime () worksheet.write_row (0,0) Title) for row, row_date in enumerate (data): worksheet.write_row (row+1, 0, row_date) print time.ctime () cursor.close () con.close () workbook.close () # the following code implements sending email msg = MIMEMultipart () # defines the attachment name att1_name= "business data" .decode ('utf-8'). Encode (' gbk') + date_now + '.xlsx' # read the attachment Report_name att1 = MIMEText (open (report_name, 'rb'). Read (),' base64', 'gb2312') att1 ["Content-Type"] =' application/octet-stream'att1 ["Content-Disposition"] = 'p_w_upload Filename=%s'% att1_name.encode ('gbk') msg.attach (att1) msg [' to'] = 'boss@126.com'msg [' from'] = 'report@126.com'msg [' subject'] = "Weekly Business data" .decode ('utf-8'). Encode (' gbk') try: server = smtplib.SMTP () server.connect ('mail.126.com') server.login (' report@126.com') '12345678') # server.sendmail (msg ['from'], msg [' to'], msg.as_string () server.quit () print 'successful.'except Exception, e: print str (e)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.