自动定时发送每日构建测试报告
【摘要】
自动定时发送每日构建测试报告
auto_send_dayly_report_email.py
# coding=utf-8""" @project: panglu_test_59 @Author:gaojs @file: auto_send_dayly_report_email.py @date:2...
自动定时发送每日构建测试报告
auto_send_dayly_report_email.py
# coding=utf-8
"""
@project: panglu_test_59
@Author:gaojs
@file: auto_send_dayly_report_email.py
@date:2022/7/14 9:43
@blogs: https://www.gaojs.com.cn
"""
import os.path
import time
import smtplib
import schedule
from selenium import webdriver
from email.mime.text import MIMEText
from selenium.webdriver.chrome.options import Options
def get_report_source_code():
"""
获取test报告源码页面
"""
if not os.path.exists('error'):
os.mkdir('error')
url = 'http://[192::1:192]/cgi-bin/test_report.pl?build=netIAG_3_2_0_7_gaojs_713'
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
driver = webdriver.Chrome(options=chrome_options)
driver.get(url)
driver.maximize_window()
source_code = driver.page_source
# return source_code:修改源码报告宽度
source_code = re.sub(r'800px', '60%', source_code)
# print(source_code)
source_code = re.sub('95', '130', source_code)
print(source_code)
with open('./test_report.html', mode='w') as fin:
fin.write(source_code)
driver.close()
return source_code
def send_email():
"""
发送test_report邮件
"""
# 获取页面源码
source_code = get_report_source_code()
# 以126邮箱为例
# ----------------发件相关参数----------------
smtpserver = 'smtp.126.com'
port = 0
sender = 'testops_jianshuai@126.com'
password = 'xxxxxxxxxxxxIAPTAQST'
# receicer = '13152027756@163.com', 'gaojs@arraynetworks.com.cn', 'gesk@arraynetworks.com.cn'
receicer = ['sunyb@arraynetworks.com.cn', 'gaojs@arraynetworks.com.cn', 'gesk@arraynetworks.com.cn', 'leixc@arraynetworks.com.cn', 'linn@arraynetworks.com.cn', '13152027756@163.com',]
# ----------------编辑邮件内容----------------
subject = 'netIAG每日构建测试报告'
body = f'<p>{source_code}<p>'
msg = MIMEText(body, 'html', 'UTF-8')
msg['from'] = sender
# 调试发送单个用户
# msg['to'] = receicer
# 发送多个用户,封号的意思就是邮件用户之间用封号隔开
msg['to'] = ';'.join(receicer)
msg['subject'] = subject
# ------------------发送邮件-----------------
smtp = smtplib.SMTP()
smtp.connect(smtpserver)
smtp.login(sender, password)
smtp.sendmail(sender, receicer, msg.as_string())
smtp.quit()
# if __name__ == '__main__':
# send_email()
# 每天凌晨发送邮件给同事
schedule.every().day.at("07:30").do(send_email)
while True:
# 启动任务
schedule.run_pending()
time.sleep(1)
文章来源: blog.csdn.net,作者:懿曲折扇情,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/qq_41332844/article/details/126837479
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)