目 录CONTENT

文章目录

自动定时发送每日构建测试报告

懿曲折扇情
2022-07-14 / 0 评论 / 6 点赞 / 95 阅读 / 506 字 / 正在检测是否收录...
温馨提示:
本文最后更新于 2022-07-24,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。
广告 广告

自动定时发送每日构建测试报告

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)


6

评论区