2024-08-30 17:18:04 -04:00
|
|
|
import pprint
|
|
|
|
|
import Apikeys
|
|
|
|
|
import requests
|
|
|
|
|
|
|
|
|
|
APIKEY = Apikeys.DATASNIPPER
|
|
|
|
|
BASEURL = "https://api.northpass.com/v2"
|
2024-09-06 16:05:32 -04:00
|
|
|
HEADERS = {"content-type": "application/json", "X-Api-Key": APIKEY}
|
2024-08-30 17:18:04 -04:00
|
|
|
PP = pprint.PrettyPrinter(indent=4)
|
|
|
|
|
ALL_LEARNERS_GROUP = "2e274dc7-3abe-4575-8b3d-0c8e73a09f44"
|
|
|
|
|
|
2024-09-06 16:05:32 -04:00
|
|
|
|
2024-08-30 17:18:04 -04:00
|
|
|
def grab_people():
|
|
|
|
|
count = 0
|
2024-09-06 16:05:32 -04:00
|
|
|
emptylist = []
|
2024-08-30 17:18:04 -04:00
|
|
|
while True:
|
|
|
|
|
count += 1
|
|
|
|
|
url = f"{BASEURL}/people?page={count}"
|
|
|
|
|
get_response = requests.get(url, headers=HEADERS)
|
|
|
|
|
resp = get_response.json()
|
|
|
|
|
nextlink = resp["links"]
|
|
|
|
|
|
|
|
|
|
for peeps in resp["data"]:
|
2024-09-06 16:05:32 -04:00
|
|
|
learner_id = peeps["id"]
|
2024-08-30 17:18:04 -04:00
|
|
|
email = peeps["attributes"]["email"]
|
|
|
|
|
groups = peeps["relationships"]["groups"]
|
2024-09-06 16:05:32 -04:00
|
|
|
if len(groups["data"]) >= 2:
|
|
|
|
|
for y in groups["data"]:
|
|
|
|
|
if ALL_LEARNERS_GROUP in y["id"]:
|
|
|
|
|
group_uuid = y["id"]
|
|
|
|
|
remove_person_from_group(learner_id, group_uuid)
|
2024-08-30 17:18:04 -04:00
|
|
|
|
|
|
|
|
if "next" not in nextlink:
|
|
|
|
|
break
|
|
|
|
|
|
2024-09-06 16:05:32 -04:00
|
|
|
def remove_person_from_group(learner_id, group_id):
|
|
|
|
|
remove_url = f"{BASEURL}/people/{learner_id}/relationships/groups"
|
|
|
|
|
print(remove_url)
|
|
|
|
|
group_payload = {"data": [{"id": group_id, "type": "membership-groups"}]}
|
|
|
|
|
print(group_payload)
|
|
|
|
|
remove_call = requests.delete(remove_url, headers=HEADERS, json=group_payload)
|
|
|
|
|
print(remove_call.status_code)
|
|
|
|
|
|
|
|
|
|
|
2024-08-30 17:18:04 -04:00
|
|
|
if __name__ == "__main__":
|
|
|
|
|
grab_people()
|