Skip to content

Commit c0dcfcc

Browse files
committed
Add example with attachments downloader
1 parent d95ee12 commit c0dcfcc

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

docs/jira.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ Manage projects
146146
# Follow the documentation of /notificationscheme/{id} resource for all details about returned value.
147147
# Use 'expand' to get details (default is None) possible values are notificationSchemeEvents,user,group,projectRole,field,all
148148
jira.get_priority_scheme_of_project(project_key_or_id, expand=None)
149-
149+
150150
# Returns a list of active users who have browse permission for a project that matches the search string for username.
151151
# Using " " string (space) for username gives All the active users who have browse permission for a project
152152
jira.get_users_with_browse_permission_to_a_project(self, username, issue_key=None, project_key=None, start=0, limit=100)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from atlassian import Jira
2+
import os
3+
4+
""" Download the attachments from tickets """
5+
6+
JIRA_URL = "localhost:8080"
7+
JIRA_LOGIN = "admin"
8+
JIRA_TOKEN = "dsadd2c3s"
9+
10+
11+
def get_tickets(jql):
12+
pass
13+
14+
15+
if __name__ == "__main__":
16+
jira = Jira(url=JIRA_URL, username=JIRA_LOGIN, token=JIRA_TOKEN)
17+
jql = "project = DOC"
18+
tickets = jira.jql(jql=jql, fields=["key,attachment"], limit=1000).get("issues")
19+
20+
for ticket in tickets:
21+
mail_folder = "tickets"
22+
if not os.path.exists(mail_folder):
23+
os.makedirs(mail_folder)
24+
key = ticket.get("key")
25+
attachments = ticket.get("fields").get("attachment")
26+
27+
for attachment in attachments:
28+
dest_folder = mail_folder + "/" + key
29+
if not os.path.exists(dest_folder):
30+
os.makedirs(dest_folder)
31+
filename = attachment.get("filename")
32+
author = attachment.get("author").get("emailAddress")
33+
attachment_id = attachment.get("id")
34+
content_url = attachment.get("content")
35+
session = jira._session
36+
response = session.get(url=content_url)
37+
38+
if response.status_code != 200:
39+
continue
40+
with open(dest_folder + "/" + filename, "wb") as f:
41+
print(f"Saving for {key} the file {filename}")
42+
f.write(response.content)

0 commit comments

Comments
 (0)