Artera templates. Chubb Templates. Anthology small changes to GAS scripts.

This commit is contained in:
Norm Rasmussen
2024-07-10 16:52:16 -04:00
parent c80150b945
commit 622310f627
6 changed files with 109 additions and 23 deletions

View File

@ -239,24 +239,30 @@ def bulk_remove_and_enroll(person_list, group_list):
time.sleep(2)
cprint("Sleep Complete. Hold on to your butts!", 'yellow')
# Re-enroll everyone back into all the groups
#payload = {"payload": {"person_ids": person_list, "group_ids": group_list}}
#cprint(f"{payload}", 'green')
#url = BASEURL + "bulk/people/membership/"
# Re-enroll everyone back into all the groups by creating subset groups
# Trying to do everyone at once (143 ppl * 54 groups) resulted in payloads that are too big
# Doing the subsets of 25 ppl each did not yield any errors.
composite_list = [person_list[x:x+25] for x in range(0, len(person_list),25)]
for people_subset in composite_list:
payload = {"payload": {"person_ids": people_subset, "group_ids": group_list}}
cprint(f"{payload}", 'green')
url = BASEURL + "bulk/people/membership/"
# The above is commented out because I kept getting a 413 error of too much content
# Changing this to enroll each person.... one at a time.
miniload = []
for groupuuid in group_list:
tmpload = {"type":"membership-groups","id":groupuuid}
miniload.append(tmpload)
print(len(person_list))
for person in person_list:
url = BASEURL + f"people/{person}/relationships/groups"
payload = { "data": miniload }
# But this is slow and didn't work. It actually just stopped working after around 30 people.
# miniload = []
# for groupuuid in group_list:
# tmpload = {"type":"membership-groups","id":groupuuid}
# miniload.append(tmpload)
#
# print(len(person_list))
# for person in person_list:
# url = BASEURL + f"people/{person}/relationships/groups"
# payload = { "data": miniload }
try:
cprint(f"Trying for person: {person}", 'green')
cprint(f"With payload: {payload}", 'blue')
response = requests.post(url, headers=HEADERS, json=payload)
response.raise_for_status()
except requests.exceptions.HTTPError as err:
@ -265,10 +271,12 @@ def bulk_remove_and_enroll(person_list, group_list):
cprint("Timeout Error", 'red')
except requests.exceptions.TooManyRedirects:
cprint("Too Many Redirects Error", 'red')
except requests.exceptions.ChunkedEncodingError as ex:
cprint(f"Invalid chunk encoding {str(ex)}", 'yellow')
finally:
cprint(response.status_code, 'yellow')
cprint(response.text, 'yellow')
cprint("Okay, let's see how that went.", 'red')
if __name__ == "__main__":
grab_person_group_ids()