-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_user.py
56 lines (46 loc) · 1.42 KB
/
create_user.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from openpyxl import load_workbook
import re
import jira
from jira import JIRA
import sys
import os
import tkinter.filedialog
# Jira Server Connection
options = {
'server': 'YOUR_DOMAIN'}
# Auth
try:
jira = JIRA(options, basic_auth=('JIRA_USER_NAME', 'JIRA_PASSWORD'))
except BaseException as Be:
print(Be)
props = jira.application_properties()
regex = re.compile(r'^.*?(?=@)')
user_input = tkinter.filedialog.askopenfilename()
if os.path.exists(user_input):
workbook = load_workbook(user_input)
else:
assert os.path.exists(
user_input), "File couldn't be found at, "+str(user_input)
first_sheet = workbook.get_sheet_names()[0]
worksheet = workbook.get_sheet_by_name(first_sheet)
names = []
emails = []
usernames = []
i = 0
for row in worksheet.iter_rows():
if row[0].row > 1:
names.append(row[1].value)
emails.append(row[2].value)
usernames.append(row[1].value.lower().replace(' ','.'))
try:
jira.add_user(usernames[i], emails[i], directoryId=1, password=None,
fullname=names[i], notify=True, active=True, ignore_existing=True)
except BaseException as Be:
print ('User Already Exists! : ',usernames[i])
# print(Be)
try:
jira.add_user_to_group(usernames[i], 'USER_GROUP')
except BaseException as Be:
print (Be)
print ('User added: ',usernames)
i += 1