diff --git a/python/upload_users_to_group.py b/python/upload_users_to_group.py index 627e1e7b..ca51cf3d 100644 --- a/python/upload_users_to_group.py +++ b/python/upload_users_to_group.py @@ -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") \ No newline at end of file + ## 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") \ No newline at end of file