Cin7 Templates, DVU templates, and G2 templates. Finished the mass delete script. Fun fact, dev docs are wrong... it's not a 15,000 limit, but 1500.

This commit is contained in:
Norm Rasmussen
2024-05-10 16:39:37 -04:00
parent fa3ab13579
commit 3820969cc2
11 changed files with 245 additions and 62 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,5 @@
import Apikeys
import json
import requests
import pandas as pd
import pprint
@ -8,10 +9,24 @@ df = pd.DataFrame()
BASEURL = "https://api.northpass.com/v2"
LEARNFILTER = "?filter[partnerships_type][eq]=Partnerships::Learner"
APIKEY = Apikeys.SANDATA
HEADERS = {"accept": "application/json", "X-Api-Key": APIKEY}
HEADERS = {"accept": "application/json", "content-type": "application/json", "X-Api-Key": APIKEY}
PERSON_GROUPS = []
PPL_DELETIONS = []
GROUPS_LIST = []
ADMINS_NOT_TO_DELETE = [
"269b4e46-74fa-49f9-b1a3-59a15180b377",
"23eb155c-395f-40a5-adb8-ef348bc85051",
"cebe6de7-af0d-46cb-bf0a-a461fb0bed63",
"e134030d-a2a9-4de2-b4d5-87081feee18a",
"65b6924b-e0b3-4e8d-a9ff-140fb9de9453",
"1cc4762e-3a6d-48b5-a8bf-bbe98e00c72e",
"5c457837-5ad5-486e-86b7-ea65353565b0",
"5e89fba5-3d12-4961-af46-2f4f131e7387",
"b0098337-7b7e-45e5-b645-e71c40387cbb",
"c111dc44-470e-4c74-a7ce-688dff5e3476",
"a6c6469b-8978-4899-a9c8-bbc5cdb29e5e",
]
def get_groups():
count = 1
@ -31,7 +46,6 @@ def get_groups():
else:
if members > 0:
grouple = (id, group_name, members)
print(grouple)
GROUPS_LIST.append(grouple)
if "next" not in nextlink:
@ -39,6 +53,7 @@ def get_groups():
get_ppl_from_groups(GROUPS_LIST)
def get_ppl_from_groups(GROUPS_LIST):
for single_group in GROUPS_LIST:
print(single_group)
@ -52,13 +67,102 @@ def get_ppl_from_groups(GROUPS_LIST):
for data in groupson["data"]:
id = data["relationships"]["person"]["data"]["id"]
print(id)
if id in ADMINS_NOT_TO_DELETE:
pass
else:
PPL_DELETIONS.append(id)
if "next" not in nextlink:
break
print("Deleting People.... Hold on to your butts.")
if len(PPL_DELETIONS) > 1500:
for chunk in range(0, len(PPL_DELETIONS), 1500):
i = chunk
delete_url = f"{BASEURL}/bulk/people/delete"
chunk_to_del = PPL_DELETIONS[i:i+1500]
payload = { "payload": chunk_to_del }
print(payload)
try:
del_resp = requests.post(delete_url, json=payload, headers=HEADERS)
print(del_resp)
if del_resp.status_code == 400:
print(
f"Issue with Group: {single_group[1]}... {del_resp.status_code} - {del_resp.text}"
)
print("Writing person IDs to file...")
with open("./Sandata_errors.txt", "a") as file:
file.write(f"{single_group}... \n {payload}")
file.close()
if del_resp.status_code == 401:
print(
f"Issue with Group: {single_group[1]}... {del_resp.status_code} - {del_resp.text}"
)
print("Writing person IDs to file...")
with open("./Sandata_errors.txt", "a") as file:
file.write(f"{single_group}... \n {payload} \n")
file.close()
if del_resp.status_code == 422:
print(
f"Issue with body for Group: {single_group[1]}... {del_resp.status_code} - {del_resp.text}"
)
print("Writing person IDs to file...")
with open("./Sandata_errors.txt", "a") as file:
file.write(f"{single_group}... \n {payload} \n")
file.close()
status = str(del_resp.status_code)
if "20" in status:
print(f"Some success! Status code: {del_resp.status_code}")
except requests.exceptions.HTTPError as h:
print(f"Exception HTTPError: {h} \n Passing onto next loop.")
pass
finally:
print(f"{single_group[1]} has been completed. Moving onto next group.")
else:
delete_url = f"{BASEURL}/bulk/people/delete"
payload = { "payload": PPL_DELETIONS }
try:
del_resp = requests.post(delete_url, json=payload, headers=HEADERS)
print(del_resp)
if del_resp.status_code == 400:
print(
f"Issue with Group: {single_group[1]}... {del_resp.status_code} - {del_resp.text}"
)
print("Writing person IDs to file...")
with open("./Sandata_errors.txt", "a") as file:
file.write(f"{single_group}... \n {payload}")
file.close()
if del_resp.status_code == 401:
print(
f"Issue with Group: {single_group[1]}... {del_resp.status_code} - {del_resp.text}"
)
print("Writing person IDs to file...")
with open("./Sandata_errors.txt", "a") as file:
file.write(f"{single_group}... \n {payload} \n")
file.close()
if del_resp.status_code == 422:
print(
f"Issue with body for Group: {single_group[1]}... {del_resp.status_code} - {del_resp.text}"
)
print("Writing person IDs to file...")
with open("./Sandata_errors.txt", "a") as file:
file.write(f"{single_group}... \n {payload} \n")
file.close()
status = str(del_resp.status_code)
if "20" in status:
print(f"Some success! Status code: {del_resp.status_code}")
except requests.exceptions.HTTPError as h:
print(f"Exception HTTPError: {h} \n Passing onto next loop.")
pass
finally:
print(f"{single_group[1]} has been completed. Moving onto next group.")
def get_people():
"""
This is no longer being used.
"""
count = 0
while True:
url = f"{BASEURL}/people{LEARNFILTER}&limit=100&page={count}"
@ -95,12 +199,12 @@ def get_people():
except JSONDecodeError as e:
print(f"There was a JSON Error --> {e}")
dataerror = df.from_records(PERSON_GROUPS)
dataerror.to_csv('~/Downloads/Sandata-err-all-ppl')
dataerror.to_csv("~/Downloads/Sandata-err-all-ppl")
print(dataerror)
print(len(PERSON_GROUPS))
datadelerr = df.from_records(PPL_DELETIONS)
datadelerr.to_csv('~/Downloads/Sandata-err-ppl-to-delete')
datadelerr.to_csv("~/Downloads/Sandata-err-ppl-to-delete")
pass
finally:
pass
@ -112,12 +216,12 @@ def get_people():
break
dataframe = df.from_records(PERSON_GROUPS)
dataframe.to_csv('~/Downloads/Sandata-all-ppl')
dataframe.to_csv("~/Downloads/Sandata-all-ppl")
print(dataframe)
print(len(PERSON_GROUPS))
datadel = df.from_records(PPL_DELETIONS)
datadel.to_csv('~/Downloads/Sandata-ppl-to-delete')
datadel.to_csv("~/Downloads/Sandata-ppl-to-delete")
# def parse_groups(id, grouplist):

View File

@ -1,4 +0,0 @@
string = "["33410b8a-246b-4253-9fc0-829d67fb1834", "70b43bcf-3261-49d3-8940-0c14f6445888", "5cfc2cb6-7de1-4b33-b945-65fe72a9ddd9", "3d3de462-e29c-4a89-ae60-3a70ec1643a9","1188e41f-b4ac-4b04-9fe5-1bc87883f58b", "9de55b7b-cb41-408e-a6f5-e28d34e4815c", "09354d84-743b-44ea-a4a5-c24697170036", "8c71009d-3210-4897-92f0-cb44b6025343","6b58f46b-1191-4436-aced-67e8d7515e74", "4ea5234d-70a2-46ed-a9aa-f4bc4dfc0769"]"
response = string.replace('"', "'")
print(response)

File diff suppressed because one or more lines are too long

1
Scripts/API_Tests/tmp.md Normal file

File diff suppressed because one or more lines are too long