A small request. I'm a junior in Python and Jira but I want to learn :) I have a code from a colleague that left the company for automated report of number of incidents in last 12 months! What I want to have is number of incidents automated monthly report of 2020. Below you can find the code. What I have to change? THX!
#!/usr/bin/python3
import requests
from datetime import date
import datetime
import calendar
from utils import jira_utils, table_utils
# Method section
DEFAULT_NUMBER_OF_MONTHS= 12
def create_data_table(month):
header_row = table_utils.create_start_of_data_table_monthly_report(DEFAULT_NUMBER_OF_MONTHS)
data_rows=create_data_row('P1', month)
data_rows+=create_data_row('P2', month)
data_rows+=create_data_row('P3', month)
#data_rows+=create_data_row('P1, P2, P3', month)
end_of_table = table_utils.end_table()
return header_row + data_rows + end_of_table
def create_data_row(priority, month):
data_row='<tr><th>' + priority + '</th>'
for i in range (-1*DEFAULT_NUMBER_OF_MONTHS, 0, 1):
if month:
time_frame=table_utils.define_time_range_for_monthly_report(i)
else:
time_frame=table_utils.define_time_range_for_weekly_report(i)
row_value = calculate_total_from_jira(priority, time_frame)
data_cell='<td><p>'+str(row_value)+'</p></td>'
data_row+=data_cell
data_row+='</tr>'
return data_row
def calculate_total_from_jira(priority, time_frame):
jql_search = calculate_jira_query(time_frame, priority)
# Authenticate on Jira REST API and fetch results for reporting period
resp=jira_utils.query_jsd(jql_search)
return resp['total']
def calculate_jira_query(time_frame, priority):
start_day = time_frame['repstart']
end_day = time_frame['repend']
#print(start_day.strftime('%Y-%m-%d 00:00'))
#print(end_day.strftime('%Y-%m-%d 23:59'))
jira_query='{"jql": "project = SM AND issuetype=Incident AND createdDate >= '+ start_day+' AND createdDate <= \\\"'+ end_day +'\\\" AND priority IN ('+priority+') AND resolution NOT IN (Duplicate, Rejected) ORDER BY issuekey","startAt":0, "maxResults":1000, "fields":["total"]}'
#print(jira_query)
return jira_query
def number_of_incidents(month):
data_table = create_data_table(month)
return data_table