Skip to content

Commit

Permalink
Merge pull request #2 in LST/zoom_client from DATAINT-150-batch_group…
Browse files Browse the repository at this point in the history
…_member_add to master

* commit 'a6f85099d5ea7ef27125cdcbc7888b7c941361b9':
  If we add users to a group, we must also be able to remove them.
  • Loading branch information
d33bs committed Aug 25, 2020
2 parents 0e028f5 + a6f8509 commit 75bad93
Showing 1 changed file with 37 additions and 7 deletions.
44 changes: 37 additions & 7 deletions zoom_client/modules/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,51 @@ class group:
def __init__(self, controller, *args, **kwargs):
self.zoom = controller

def add_members(self, group_id, user_ids):
def add_members(self, group_id, user_emails):
# Special note: uses user emails as opposed to ID's

logging.info("Adding {} users to group with id {}".format(str(len(user_ids)), group_id))
logging.info(
"Adding {} users to group with id {}".format(str(len(user_emails)), group_id)
)

def chunks(l, n):
for i in range(0, len(l), n):
yield l[i:i + n]
yield l[i : i + n]

for chunk in list(chunks(user_ids, 30)):
for chunk in list(chunks(user_emails, 30)):
logging.info("Processing adding chunk of 30 or less users to group...")
post_data = {"members":[{"email":x} for x in chunk]}
post_data = {"members": [{"email": x} for x in chunk]}
result = self.zoom.api_client.do_request(
"post", "groups/" + group_id + "/members", "", body=json.dumps(post_data)
"post",
"groups/" + group_id + "/members",
"",
body=json.dumps(post_data),
)
# simple check to make sure we don't exceed rate limits, this needs improvement!
time.sleep(5)

return result
return result

def delete_members(self, group_id, user_ids):
# Special note: uses user ID's as oppposed to emails
logging.info(
"Removing {} users from group with id {}".format(
str(len(user_ids)), group_id
)
)

def chunks(l, n):
for i in range(0, len(l), n):
yield l[i : i + n]

for chunk in list(chunks(user_ids, 30)):
logging.info("Processing removing chunk of 30 or less users from group...")
for user_id in chunk:
result = self.zoom.api_client.do_request(
"delete", "groups/" + group_id + "/members/" + user_id, ""
)
# simple check to make sure we don't exceed rate limits, this needs improvement!
# 30 requests per second are permissable and well below actual Edu account limits
time.sleep(1)

return result

0 comments on commit 75bad93

Please sign in to comment.