New script for getting everyone who is in each group and export to CSV. Skan templates. A few other small things
This commit is contained in:
@ -25,3 +25,4 @@ FULLSTORY = "ePChrDWLegENa2qnfb259O2Ki"
|
||||
RENAISSANCE = "YFykqX1u0d3HveONc5I9CKnJ1"
|
||||
SANDATA = "HdZFoXGCFpt8NnTOzIQY0kVDj"
|
||||
LUMINATE_US = "p5fidpuedHaOlPnd8EcpxzQMG"
|
||||
SKAN = "89qJQDaFl3DvIpSSOUC5PM9V6"
|
||||
|
||||
Binary file not shown.
60
Scripts/API_Tests/get_groups_and_learners.py
Normal file
60
Scripts/API_Tests/get_groups_and_learners.py
Normal file
@ -0,0 +1,60 @@
|
||||
import requests
|
||||
import Apikeys
|
||||
import pandas as pd
|
||||
|
||||
BASEURL = "https://api.northpass.com/v2/"
|
||||
APIKEY = Apikeys.SKAN
|
||||
HEADERS = {"X-Api-Key": APIKEY, "accept": "application/json"}
|
||||
|
||||
LISTGROUPS = "groups/"
|
||||
FINALDICT = {}
|
||||
|
||||
|
||||
def get_groups():
|
||||
count = 0
|
||||
groups_list = []
|
||||
while True:
|
||||
count += 1
|
||||
groupsurl = f"{BASEURL}{LISTGROUPS}?limit=100&page={count}"
|
||||
groupsreq = requests.get(groupsurl, headers=HEADERS)
|
||||
groupson = groupsreq.json()
|
||||
nextlink = groupson["links"]
|
||||
|
||||
for grous in groupson["data"]:
|
||||
grouple = (grous["id"], grous["attributes"]["name"])
|
||||
groups_list.append(grouple)
|
||||
|
||||
if "next" not in nextlink:
|
||||
break
|
||||
|
||||
get_memberships(groups_list)
|
||||
|
||||
|
||||
def get_memberships(groups_list):
|
||||
for gids, ginames in groups_list:
|
||||
count2 = 0
|
||||
members_list = []
|
||||
while True:
|
||||
count2 += 1
|
||||
group_uuid = gids
|
||||
LISTMEMBERS = f"{group_uuid}/memberships"
|
||||
membersurl = f"{BASEURL}{LISTGROUPS}{LISTMEMBERS}?limit=100&page={count2}"
|
||||
memreq = requests.get(membersurl, headers=HEADERS)
|
||||
members = memreq.json()
|
||||
nextlink = members["links"]
|
||||
|
||||
for person in members["included"]:
|
||||
email = person["attributes"]["email"]
|
||||
members_list.append(email)
|
||||
|
||||
if "next" not in nextlink:
|
||||
break
|
||||
FINALDICT[ginames] = members_list
|
||||
|
||||
df = pd.DataFrame.from_dict(FINALDICT, orient='index')
|
||||
print(df)
|
||||
df.to_csv("~/Downloads/Skan_Groups_Members.csv")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
get_groups()
|
||||
Reference in New Issue
Block a user