Skip to content
This repository has been archived by the owner on Sep 25, 2020. It is now read-only.

Commit

Permalink
Upload CSV and add users to a Group -- added group name rather than ID.
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-lyons committed Jul 30, 2021
1 parent 45b1129 commit 56c4c47
Showing 1 changed file with 33 additions and 27 deletions.
60 changes: 33 additions & 27 deletions python/upload_users_to_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,38 @@
### Depending on the cleanliness of your source of emails, you may want to add more error handling
### EG check for structure, add users without Looker accounts to an output file, or even pass them into another endpoint where you create an account.

def add_csv_of_users_to_group(group_id:int, file_path:str):
data = []
i=0
with open(file_path) as f:
reader = csv.reader(f, delimiter=' ')
for row in reader:
data.append(str(row[i]))

## loops through list and searches user
## grabs user id and passes that through add user to group
try:
for email in data:
for user in sdk.search_users(email=email):
#print(user.email)
if user.id:
sdk.add_group_user(group_id=group_id, body=models40.GroupIdForGroupUserInclusion(user_id= user.id))
else:
pass
def add_csv_of_users_to_group(group_name:str, file_path:str):
group = sdk.search_groups(name=group_name)
group = group[0]
if group:
data = []
i=0
with open(file_path) as f:
reader = csv.reader(f, delimiter=' ')
for row in reader:
data.append(str(row[i]))

except KeyError:
print('Key error \n')
pass
except TypeError:
print('Type error \n')
pass
except IndexError:
print('Index error \n')
pass
add_csv_of_users_to_group(121, "test.csv")
## loops through list and searches user
## grabs user id and passes that through add user to group
try:
for email in data:
for user in sdk.search_users(email=email):
#print(user.email)
if user.id:
sdk.add_group_user(group_id=group.id, body=models40.GroupIdForGroupUserInclusion(user_id= user.id))
else:
pass

except KeyError:
print('Key error \n')
pass
except TypeError:
print('Type error \n')
pass
except IndexError:
print('Index error \n')
pass
else:
print("Group does not exist")
add_csv_of_users_to_group("all but 1", "test.csv")

0 comments on commit 56c4c47

Please sign in to comment.