python实战三:通过任务计划定期获取jira数据并保存到csv

配置任务计划,每天获取一次jira.bug统计数据并保存到csv,为后续制作报表提供基础数据

任务计划配置方法:
1.打开任务计划
开始-所有程序-附件-系统工具-任务计划程序
2.新建任务计划程序库:python_auto
3.在其下建立新的任务计划:getdata
设置执行脚本时间:
python实战三:通过任务计划定期获取jira数据并保存到csv_第1张图片
设置脚本路径:
python实战三:通过任务计划定期获取jira数据并保存到csv_第2张图片


获取jira数据的脚本:

脚本能用,但还有很大改进空间

from jira import JIRA 
import csv
import time
import os

class JiraData(object):
    """docstring for JiraData"""
    bug_trend=[]    
    jira = ''
    start_date = '2015-03-15'
    curr_date = time.strftime("%Y-%m-%d", time.localtime())
    file_name = 'D:/python/bugstat/data/bug_trend.csv'

    def __init__(self):
        super(JiraData, self).__init__()
        self.jira = JIRA('http://localhost/jira/',basic_auth=('username', 'password'))
        #创建jira链接

    #获取bug趋势统计数据写入到csv文件中,追加
    def write_CSVFile(self, bug_data,file_type):
        with open(self.file_name, file_type, newline='') as csvfile:
            spamwriter = csv.writer(csvfile, delimiter=',')
            spamwriter.writerow(bug_data)

    def get_bug_trend_data(self):


        if not os.path.exists(self.file_name):          
            self.write_CSVFile(['create_date','All','Resolved','Closed'],'a')

        self.bug_trend.append(self.curr_date)
        self.bug_trend.append(len(self.jira.search_issues("project = VJFOUR AND issuetype = Bug AND created >= %s " %self.start_date)))
        self.bug_trend.append(len(self.jira.search_issues("project = VJFOUR AND issuetype = Bug AND status in (Resolved, Closed) AND created >= %s " %self.start_date)))
        self.bug_trend.append(len(self.jira.search_issues("project = VJFOUR AND issuetype = Bug AND status = Closed AND created >= %s " %self.start_date)))

        self.write_CSVFile(self.bug_trend,'a')


if __name__ == '__main__':
    jd = JiraData()
    jd.get_bug_trend_data()

你可能感兴趣的:(python实战三:通过任务计划定期获取jira数据并保存到csv)