Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Get worklog of individual user from jira using python- Updated

Himanshu_Pant April 9, 2018

I want to do something like below piece of code :- want to iterate for number of worklogs entries for particular value.key

I want to get details logged by user on daily basis and details should be of last nine weeks.

Could you please suggest and check my code that I am going in right direction or not.

example :-

Key  worklogtime  logged_date   logged_by

203    2h                 2018-04-08       xyz

203    1h                 2018-04-07       abc

201     4h                2018-04-07       blaah

 

 

 

Piece of Code:-

 

import jira.client
from jira.client import JIRA

options = {'server': 'https:/example.com', 'verify':False}
jira = JIRA(options, basic_auth=('user', 'password))
issues_in_project = jira.search_issues('project=11372 and Assignee in(xyz,abc)',maxResults=1000)

i = 0
for value in issues_in_project:
for i in value:
print value.fields.worklog.worklogs[i].timeSpent, value.fields.worklog.worklogs[i].updated,value.fields.worklog.worklogs[i].updateAuthor,value.key
i = i + 1

Got error :-

Traceback (most recent call last):
File "jira_test_Time_log.py", line 89, in <module>
for i in value:

TypeError: 'Issue' object is not iterable

 

But I was able to get results from below for 2 indexes:-

for value in issues_in_project:

print value.fields.worklog.worklogs[0].timeSpent, value.fields.worklog.worklogs[0].updated,value.fields.worklog.worklogs[0].updateAuthor,value.key

print value.fields.worklog.worklogs[1].timeSpent, value.fields.worklog.worklogs[1].updated,value.fields.worklog.worklogs[1].updateAuthor,value.key

 

 

2 answers

0 votes
Jay Wang
Contributor
February 2, 2023

Working code. Loop through all project, all issue and then all worklog.

 

from jira import JIRA
import pandas as pd

email = 'john.robert@newhealthcare.com'                                         # Jira username
api_token = 'OgVDNpjLgGTMTYovSC2Z196D'                                          # Jira API token
server = 'https://newhealthcare.atlassian.net/'                                 # Jira server URL    

jira = JIRA(options = {'server': server}, basic_auth = (email, api_token))

# Get all projects viewable by anonymous users.
projects = jira.projects()

# JSON to pandas DataFrame
allIssues = pd.DataFrame()

listOfWorklog = pd.DataFrame()
list = {}

for project in projects:
    # if project.key == 'SAD':
        issues_in_proj = jira.search_issues('project = ' + project.key, maxResults = 0)  
        for issue in issues_in_proj:
          worklogs = jira.worklogs(issue.key)
          for j in range(len(worklogs)):                          #innder loop for single issue
              list = {
                      'issue': issue.key,
                      'author': worklogs[j].author,
                      'started': worklogs[j].started,
                      'created': worklogs[j].created,
                      'updated': worklogs[j].updated,
                      'timespent': worklogs[j].timeSpentSeconds
                  }
              listOfWorklog = listOfWorklog.append(list, ignore_index=True)

listOfWorklog.to_csv('listOfWorklog.csv', index = False)
0 votes
Shaun S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 10, 2018

Himanshu,

 

I added the code to the other question you raised, but I'll include here for visibility.  You can iterate over the index with the following code.

for value in issues_in_project:
log_entry_count = len(value.fields.worklog.worklogs)
for i in range(log_entry_count):
print value.key, value.fields.worklog.worklogs[i].timeSpent, value.fields.worklog.worklogs[i].updated, value.fields.worklog.worklogs[i].updateAuthor

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events