前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Python生成html邮件

Python生成html邮件

作者头像
py3study
发布2020-01-07 15:52:40
1.5K0
发布2020-01-07 15:52:40
举报
文章被收录于专栏:python3

最近在学习Python,这是我第一个Python脚本。没有技术含量,之前不知道zip()函数,想让2个结果对应起来,弄了好久,后来问了做php的同事,才知道。

需求:实现爬虫每次下载完成后生成html统计邮件,发送到邮箱;

代码语言:javascript
复制
#!/usr/bin/env python
#coding:utf8
import os
td = """            <td style="border-style:inset;border-color:#808080;padding:0px;border-width:1px">"""
num = 1
os.system("ls -lth /data0/backup/video/* |awk '{print $1\" \"$3\" \"$NF\" \"$6}'> /tmp/fileinfo.log")
os.system("ls -lth /data0/backup/video/* |awk '{print $5}' > /tmp/filesize.txt")
maketime=os.popen('date +%Y-%m-%d" "%H":"%M').read()
number=os.popen('ls /data0/backup/video/|wc -l').read()
print """
<div><span style="line-height: 1.5;">备份时间:%s </span></div>
<div><span style="line-height: 1.5;">总文件数:%s </span></div>
<div><span style="line-height: 1.5;">文件列表:</span></div>"""%(maketime,number)
print """<table border="1" cellspacing="0px" style="text-align: center; border: 1px outset rgb(128, 128, 128); border-collapse: collapse; width: 60%; border-spacing: 0px;">
<tbody>"""
file=open('/tmp/fileinfo.log')
size=open('/tmp/filesize.txt')
filename=zip(size,file)
print "        <th>编号</th>"
#print "        <th>用户</th>"
print "        <th>时间</th>"
print "        <th>大小</th>"
print "        <th>文件</th>"
for k,v in filename:
info = v.split()
s = k.split()
print "        <tr>"
print  "%s%s</td>"%(td,num)
#print  "%s%s</td>"%(td,info[1])
print  "%s%s</td>"%(td,info[3])
print  "%s%s</td>"%(td,s[0])
print  "%s%s</td>"%(td,info[2])
print "        </tr>"
num = num+1
print """    </tbody>
</table> <div style="text-align: center;"><span style="line-height: 1.7;"></span></div>
"""

 实现效果

wKioL1Mqqgfy8uviAAU9SffsJBU933.jpg
wKioL1Mqqgfy8uviAAU9SffsJBU933.jpg

附Linux下发送html邮件方式:

mail -s "$(echo -e "title\nContent-Type: text/html")" mail@qq.com

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/09/10 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档