#!/usr/bin/python
# -*- coding: UTF-8 -*-
import datetime
import smtplib
import string
Yesterday=datetime.datetime.now() - datetime.timedelta(days=1)
yesterday=Yesterday.strftime('%Y-%m-%d')
logfile="DataApiInfo_%s-0.log" %yesterday
sumline=0
type1=0
type2=0
type3=0
type4=0
type5=0
type6=0
type7=0
type8=0
with file(logfile,'r') as lock_f:
for line in lock_f:
if line.find("Result info") > -1:
sumline=sumline+1
else:
print "no file"
if line.find("checkResult=1") > -1:
type1=type1+1
elif line.find("checkResult=2") > -1:
type2=type2+1
elif line.find("checkResult=3") > -1:
type3=type3+1
elif line.find("checkResult=4") > -1:
type4=type4+1
elif line.find("checkResult=5") > -1:
type5=type5+1
elif line.find("checkResult=6") > -1:
type6=type6+1
elif line.find("checkResult=7") > -1:
type7=type7+1
elif line.find("checkResult=8") > -1:
type8=type8+1
HOST = "172.16.20.102" #定义smtp主机
SUBJECT = "wyeth log 统计" #定义邮件主题
TO = ["xxx@getui.com","xxx@getui.com"] #定义邮件收件人
FROM = "bi_system@getui.com" #定义邮件发件人
text = " %s 惠氏线下接口查询统计如下 \n checkResult1 num %s \n checkResult2 num %s \n checkResult3 num %s \n checkResult4 num %s \n checkResult5 num %s \n checkResult6 num %s \n checkResult7 num %s \n checkResult8 num %s \n 合计 num %s \n" %(yesterday,type1,type2,type3,type4,type5,type6,type7,type8,sumline) #邮件内容
BODY = string.join(( #组装sendmail方法的邮件主体内容,各段以"\r\n"进行分隔
"From: %s" % FROM,
"To: %s" % TO,
"Subject: %s" % SUBJECT ,
"",
text
), "\r\n")
server = smtplib.SMTP() #创建一个SMTP()对象
server.connect(HOST,"25") #通过connect方法连接smtp主机
server.starttls() #启动安全传输模式
server.login("xxx","xxx") #邮箱账号登录校验
for i in range(0,2):
server.sendmail(FROM, TO[i], BODY) #邮件发送
server.quit()
python 统计文档
最新推荐文章于 2022-04-28 15:37:09 发布