Finished Datasnipper script. Some template stuff.
This commit is contained in:
@ -4,12 +4,14 @@ import requests
|
||||
|
||||
APIKEY = Apikeys.DATASNIPPER
|
||||
BASEURL = "https://api.northpass.com/v2"
|
||||
HEADERS = { "content-type": "appliation/json", "X-Api-Key": APIKEY }
|
||||
HEADERS = {"content-type": "application/json", "X-Api-Key": APIKEY}
|
||||
PP = pprint.PrettyPrinter(indent=4)
|
||||
ALL_LEARNERS_GROUP = "2e274dc7-3abe-4575-8b3d-0c8e73a09f44"
|
||||
|
||||
|
||||
def grab_people():
|
||||
count = 0
|
||||
emptylist = []
|
||||
while True:
|
||||
count += 1
|
||||
url = f"{BASEURL}/people?page={count}"
|
||||
@ -18,18 +20,26 @@ def grab_people():
|
||||
nextlink = resp["links"]
|
||||
|
||||
for peeps in resp["data"]:
|
||||
id = peeps["id"]
|
||||
learner_id = peeps["id"]
|
||||
email = peeps["attributes"]["email"]
|
||||
groups = peeps["relationships"]["groups"]
|
||||
if len(groups['data']) >= 2:
|
||||
for y in groups['data']:
|
||||
if ALL_LEARNERS_GROUP in y['id']:
|
||||
print(email, id)
|
||||
# if 'ecb95453-7196-4392-8a24-392bf14b0480' in y:
|
||||
|
||||
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)
|
||||
|
||||
if "next" not in nextlink:
|
||||
break
|
||||
|
||||
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)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
grab_people()
|
||||
|
||||
Reference in New Issue
Block a user