I am doing automation in python for jira with the addition of jql search inside the service As a result: two JQL queries, one to search for “closed tickets” and the second to search for “created tickets”
But as a result, I can’t add rows now.
#Day 0 - current day , Day '-1' - Yesterday jql_day = ['','-1','-2','-3'] jql_list_one_str = [] jql_list_two_str = [] action = ['resolved','created'] for i in jql_day: jql_str = 'project = MRCHNT AND '+ action[0]+' >= startOfDay(' + i + ')', 'project = MRCHNT AND '+ action[1]+' >= startOfDay(' + i + ')' jql_list_one_str.append(jql_str) jql_str_2 = 'AND '+ action[0] +' <= startOfDay(' + i + ')','AND '+ action[1] +' <= startOfDay(' + i + ')' jql_list_two_str.append(jql_str_2) # jql_request = [' '.join(x) for x in zip(jql_list_one_str[1:], jql_list_two_str[:-1])]# Split list # jql_request.insert(0,jql_list_one_str[0]) print(jql_list_one_str,jql_list_two_str)
Expected Result:
1 list resolved: 'project = MRCHNT AND resolved >= startOfDay()' 'project = MRCHNT AND resolved >= startOfDay(-1) AND resolved <= startOfDay()' 'project = MRCHNT AND resolved >= startOfDay(-2) AND resolved <= startOfDay(-1)' 'project = MRCHNT AND resolved >= startOfDay(-3) AND resolved <= startOfDay(-2)'
2 list created: 'project = MRCHNT AND created >= startOfDay() 'project = MRCHNT AND created >= startOfDay(-1) AND created <= startOfDay()' 'project = MRCHNT AND created >= startOfDay(-2) AND created <= startOfDay(-1)' 'project = MRCHNT AND created >= startOfDay(-3) AND created <= startOfDay(-2)'
I got two lists inside with tuples. enter image description here
“second result” enter image description here
Advertisement
Answer
You should use f-strings to resolve this issue.
jql_day = ['','-1','-2','-3'] jql_list_one_str = [] jql_list_two_str = [] action = ['resolved','created'] for i in jql_day: jql_str = [f'project = MRCHNT AND {action[0]} >= startOfDay({i})', f'project = MRCHNT AND {action[1]} >= startOfDay({i})'] jql_list_one_str.append(jql_str) jql_str_2 = [f'AND {action[0]} <= startOfDay({i})', f'AND {action[1]} <= startOfDay({i})'] jql_list_two_str.append(jql_str_2)
To then get the relevant strings you are interested in I should think you should use:
created = [] resolved = [] for idx, day in enumerate(jql_day): if idx == 0: string1 = jql_list_one_str[idx][0] string2 = jql_list_one_str[idx][1] else: string1 = jql_list_one_str[idx][0] + " , " + jql_list_two_str[idx-1][0] string2 = jql_list_one_str[idx][1] + " , " + jql_list_two_str[idx-1][1] resolved.append(string1) created.append(string2) print(resolved) print(created)