jira小工具与邮件发送

Posted niuniumother

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jira小工具与邮件发送相关的知识,希望对你有一定的参考价值。

代码示例

#!/usr/bin/python
# -*- coding: UTF-8 -*-
# coding:utf8

import requests
import datetime
import smtplib
from email.mime.text import MIMEText
from email.header import Header


class JiraTest(object):

    # def __init__(self):
    #     pass


    # 获取需求列表
    def query_wf_project(param):
        payload=
        'jql': 'issuetype in (业务需求, 技术需求) AND 需求类型 = 项目 AND status not in (发布上线, Done, 不解决, 废弃) ORDER BY createdDate ASC',
        'startAt': 0, 'expand': 'changelog'
        apiUrl = 'http://wf.vdian.net/rest/api/2/search'
        r = requests.get(apiUrl, params=payload)
        issues = r.json()["issues"]
        total = r.json()["total"]
        print(r.url)
        return issues

    def publish_delay(publistTime, testTime, created):
        desc = ""
        if testTime:
            planTestTime = datetime.datetime.strptime(testTime, '%Y-%m-%d')
            nowTimeStamp = datetime.datetime.now()
            # 提测延期部分需要优化,跟状态流转记录比较
            if nowTimeStamp > planTestTime:
                desc = "提测延期" + str((nowTimeStamp - planTestTime).days) + "天;"
            else:
                desc = ""
        else:
            desc = "计划提测时间未填写;"
        if publistTime:
            planTimeStamp = datetime.datetime.strptime(publistTime, '%Y-%m-%d')   #由字符串转为日期型的函数为:datetime.datetime.strptime()
            nowTimeStamp = datetime.datetime.now()
            # print(planTimeStamp)
            # print(nowTimeStamp)
            if nowTimeStamp > planTimeStamp:
                desc = desc + "发布延期" + str((nowTimeStamp - planTimeStamp).days) + "天;"
            else:
                desc = desc + ""
        else:
            desc = desc + "计划发布时间未填写;"
        ##项目时间超过2个月
        nowTimeStamp = datetime.datetime.now()
        createdStamp = datetime.datetime.strptime(created, '%Y-%m-%d')
        if (nowTimeStamp - createdStamp).days > 60:
            desc = desc + "项目创建时间超过2个月;"
        if desc.strip() == "":
            return "项目进度正常"
        return desc

    # 发送邮件
    def send_notify(email, key, title, res, subject):
        # 第三方 SMTP 服务
        mail_host = 'smtp.126.com'  # 设置服务器
        mail_user = 'fengyanhuaivy@126.com'  # 用户名
        mail_pass ='126password'  # 126邮箱对应的口令
        sender = 'fengyanhuaivy@126.com'
        receivers = 'XX@qq.com'  # 接收邮件,可设置为你的QQ邮箱或者其他邮箱
        mail_msg=''
        mail_msg = mail_msg.replace("TEST-412", key)
        mail_msg = mail_msg.replace("标题", title)
        mail_msg = mail_msg.replace("项目描述", res)
        message = MIMEText(mail_msg, 'html', 'utf-8')

        message['From'] = 'xx@126.com'
        message['to'] = 'xx@qq.com'
        message['Subject'] = Header(subject, 'utf-8')

        smtpObj = smtplib.SMTP()
        smtpObj.connect(mail_host)  # 25 为 SMTP 端口号
        smtpObj.login(mail_user, mail_pass)
        smtpObj.sendmail(sender, receivers, message.as_string())
        smtpObj.quit()
        print('邮件发送成功')

    issues=query_wf_project(0)
    for issue in issues:

        #url
        url = "http://wf.vdian.net/browse/"+(issue["key"])
        #标题
        title = (issue["fields"]["summary"])
        #报告人
        reporter = (issue["fields"]["reporter"]["displayName"])
        #创建日期
        created = issue["fields"]["created"][0:10]
        #产品
        project = (issue["fields"]["project"]["name"])
        #产品线
        projectCategory = (issue["fields"]["project"]["projectCategory"]["name"])
        #计划提测时间
        testPlanTime = (issue["fields"]["customfield_10200"])
        #计划上线时间
        publistPlanTime = (issue["fields"]["customfield_10109"])
        #进度
        status = (issue["fields"]["status"]["name"])
        #经办人
        assignee = (issue["fields"]["assignee"]["displayName"])
        #测试人员
        if issue["fields"]["customfield_10108"]:
            tester = (issue["fields"]["customfield_10108"][0]["displayName"])
        else:
            tester = ("无测试人员")
        delay = publish_delay(publistPlanTime, testPlanTime, created)
        print('延期信息打印',delay)
    send_notify('fengyanhua@weidian.com', 'WDAPP-8503', 'title', 'desc', 'subject')

以上是关于jira小工具与邮件发送的主要内容,如果未能解决你的问题,请参考以下文章

MYSQL自动备份并发送邮件工具

Office 365 小技巧:将 重要的电子邮件发送到OneNote保存

MSN邮箱的服务器信息,发送邮件(SMTP)与接收邮件(POP3)如何设置?

outlook 2013撤消已经发送的邮件

python 发送邮件小程序

Kettle工具 发送邮件 运行日志