Fixed knowledgestate properties for anthology.
This commit is contained in:
@ -433,3 +433,8 @@ Two items from KC:
|
||||
* Subset of Claremont domains are in the academy
|
||||
|
||||
KC Question: When the categories are established in the filters, can we programatically re-assign categories to all 800 courses? Or does it need to be done manually?
|
||||
|
||||
|
||||
KS1:
|
||||
Anthology Academic Economics: Essential, Anthology Academic Economics: Enhanced, Anthology Accreditation: Essential, Anthology Accreditation: Enhanced, Anthology 101: Essential, Anthology Baseline: Essential, Anthology Baseline: Enhanced, Anthology Beacon: Essential, Anthology Course Evaluations: Essential, Anthology Course Evaluations: Enhanced, Anthology Digital Assistant: Essential, Anthology Digital Assistant: Enhanced, Anthology Encompass: Essential, Anthology Encompass: Enhanced, Anthology Encompass: Enhanced+, Anthology Engage: Essential, Anthology Engage: Enhanced, Anthology Engage: Enhanced+, Anthology Evaluate: Essential, Anthology Evaluate: Enhanced, Anthology Finance & HCM: Essential, Anthology Finance & HCM: Enhanced, Anthology Finance & HCM: Enhanced+, Anthology Insight: Essential, Anthology Insight: Enhanced, Blackboard Learn: Essential, Anthology Milestone: Essential, Anthology Milestone: Enhanced, Outcomes: Essential, Outcomes: Enhanced, Anthology Payroll: Essential, Anthology Payroll: Enhanced, Anthology Planning: Essential, Anthology Planning: Enhanced, Anthology Portfolio: Essential, Anthology Portfolio: Enhanced, Power BI: Essential, Power BI: Enhanced, Anthology Program Review: Essential, Anthology Program Review: Enhanced, Anthology Raise: Essential, Anthology Raise: Enhanced, Anthology Raise: Enhanced+, Anthology Reach: Essential, Anthology Reach: Enhanced, Anthology Reach: Enhanced+, Anthology Student: Essential, Anthology Student: Enhanced,
|
||||
Anthology Student: Enhanced+,
|
||||
|
||||
@ -11,120 +11,172 @@ HEADERS = {
|
||||
"content-type": "application/json",
|
||||
}
|
||||
KNOWLEDGEGROUPS = [
|
||||
'289f8d54-e487-48a0-ac43-5c51c1d0b151',
|
||||
'a71e6ca9-aaa5-45a6-9e23-3b4c2a707c3d',
|
||||
'b69916db-59e3-4b06-a5f1-d358338ed7d7',
|
||||
'3875a210-f86d-4b4a-a86a-980022374936',
|
||||
'c482c095-4d67-4673-a175-ab27a5bd959b',
|
||||
'4992b00e-0453-4060-9451-fa963f56150e',
|
||||
'3f8dc68e-1458-4199-9641-6781960e085e',
|
||||
'8585fe89-a050-4dbb-beb8-6ebd7358a970',
|
||||
'd2542667-0dbf-4680-a5af-042d70f24a55',
|
||||
'7395831e-4325-4b16-85bb-36c94f68aec0',
|
||||
'180571e8-f943-4980-8997-b3eed2a0c141',
|
||||
'2b69f2f8-d567-48c3-8bb3-22e0dc8819bd',
|
||||
'2b5267b2-ce87-4e77-ad88-5cfec80496b9',
|
||||
'483c3416-ddfb-43fe-983b-08abb6b50c62',
|
||||
'df9855d7-12ae-4170-acf6-a05cd4f52515',
|
||||
'1582d056-55fb-403b-8a65-f3b641c96b69',
|
||||
'be95bdcc-e72a-4132-8a67-9dde9bad5e2a',
|
||||
'299dd454-076d-4580-8cb9-4301997e86cd',
|
||||
'0a3412da-5f73-4738-8364-15d5919750f3',
|
||||
'197da27d-0497-40b5-b2f8-cec4124d32f6',
|
||||
'a031d9a8-e433-45cf-826a-8881644f8eac',
|
||||
'02702bf3-261c-41e0-a22d-26d3e90493a3',
|
||||
'a013fa2c-5b84-49d3-a3b4-fb80a768f37c',
|
||||
'c5ea5c83-9535-4d52-a2d0-12c101e3aee9',
|
||||
'672a0dd4-a5a0-43c1-bd40-f66cdb241ec7',
|
||||
'3b149bfe-31c5-4991-bd6c-ba4c760089d4',
|
||||
'b6ae5e37-db6a-4b79-949f-be73b216f677',
|
||||
'2f787b42-e43a-4cea-9c12-19a647e21eeb',
|
||||
'bfb708e4-18eb-47b5-afde-737f16721e9a',
|
||||
'f02032d3-3d60-4cb1-acac-855c229646c3',
|
||||
'96b24666-85f2-4f70-ae59-f5a924cc045f',
|
||||
'f7701275-cebc-482b-ac31-9cfcd93937c3',
|
||||
'fcfe4ee2-b247-4244-8cfc-f3d98d219fea',
|
||||
'c6b6d415-323e-46c1-859e-be86fd36ec48',
|
||||
'e53216bf-9815-42c7-89c1-953a7b1289a3',
|
||||
'5eeef2ff-1616-43bb-a0c1-aa84ad551824',
|
||||
'c78fffea-32b8-477e-81e9-7133119d9207',
|
||||
'59ccfdeb-8a8a-4693-b4fa-27034192071c',
|
||||
'849f1551-604a-4b5c-9b5d-e2771eed488c',
|
||||
'cf5d1920-9618-43f3-8dac-53954d19a956',
|
||||
'4d0bf08e-3dda-4a2e-8213-72a020873a03',
|
||||
'e48c8995-6a64-45c1-ae62-ba96fcc01542',
|
||||
'0ef5fdd2-718c-47d2-88bc-2d0193b18530',
|
||||
'8302b674-c728-42d2-9ba3-908b4d970436',
|
||||
'ab461de6-1137-4548-87bf-f9dd78905417',
|
||||
'0b26d479-d9a7-4e07-aa2f-4893467f41c2',
|
||||
'604dd8b8-175a-4a74-93d2-28760f1d1835',
|
||||
'26c5277c-440a-4dea-b625-beb986cff673',
|
||||
'8e33adf0-5932-4535-90c7-10fa04e97201',
|
||||
'1ef34494-4d48-4b69-9819-a22c5870fc24',
|
||||
'b2b8d7aa-06e8-4ed5-bc9b-cb9ce0e81309',
|
||||
'e4017ee0-6141-4145-816f-ed68ee6931bc',
|
||||
'84d32175-8cb8-4fb0-95cc-6ae13d40aaaa',
|
||||
'27489e34-b04c-410e-99a2-0d93e2e42fbf',
|
||||
'65cff7cb-0a29-4c0c-9280-76af55d1432d',
|
||||
'e5e8565f-80e2-4462-b687-56f6d64f95e4',
|
||||
'27accc37-c3fd-465f-99cd-3e131081aeca',
|
||||
'32e112bd-5495-4399-85dd-1925e1ccbba5',
|
||||
'dc50ca43-5071-45b3-bf42-e1e64416ffd0',
|
||||
'950a6345-5a13-4931-8d82-eac6adef03e3',
|
||||
'700640e7-0de3-49dc-b441-4efff8ad33ba',
|
||||
'5f35e542-a8cf-4422-8e87-466cdca62864',
|
||||
'f50cb362-2f86-44eb-89e6-bea6ecbaf89f',
|
||||
'31a7cbe0-6aa6-403b-a561-6bc4fa81c0b1',
|
||||
'd694804c-ae1a-4db0-b5fc-2497e43abb6f',
|
||||
'a008a4e6-e026-4a1c-8aef-eea78c41b029',
|
||||
'4575114c-1e63-41b1-8953-67d3ce3ed3e6',
|
||||
'853de4bd-6f6a-4d1d-980a-b67eb1b0e876',
|
||||
'cd0fa4e0-2d24-4b35-918a-33baa736015e',
|
||||
'933baf03-3664-4c33-bd97-208a9f7ab78b',
|
||||
'55bae3db-5f62-4be3-823a-bcb429b8a2b2',
|
||||
'4754b85b-e7a6-41a8-b0e9-5e02c58ebc38',
|
||||
'33f4fc73-102d-492e-9b0a-383d0b0f68b0',
|
||||
'fa8914be-0986-460c-884d-9973a9622045',
|
||||
'b9f734fa-de0d-4a0b-9ce2-c092126e1d8d',
|
||||
'448f3335-cf11-4e7a-9939-c734861d16e3',
|
||||
'106775db-a00d-4956-bf27-97ea269bb001',
|
||||
'594cd6c0-17db-4241-be56-ad28a8db4f7b',
|
||||
'95f7b67d-3ba8-4d18-bcbb-3e02f7bfaf7a',
|
||||
"289f8d54-e487-48a0-ac43-5c51c1d0b151",
|
||||
"a71e6ca9-aaa5-45a6-9e23-3b4c2a707c3d",
|
||||
"b69916db-59e3-4b06-a5f1-d358338ed7d7",
|
||||
"3875a210-f86d-4b4a-a86a-980022374936",
|
||||
"c482c095-4d67-4673-a175-ab27a5bd959b",
|
||||
"4992b00e-0453-4060-9451-fa963f56150e",
|
||||
"3f8dc68e-1458-4199-9641-6781960e085e",
|
||||
"8585fe89-a050-4dbb-beb8-6ebd7358a970",
|
||||
"d2542667-0dbf-4680-a5af-042d70f24a55",
|
||||
"7395831e-4325-4b16-85bb-36c94f68aec0",
|
||||
"180571e8-f943-4980-8997-b3eed2a0c141",
|
||||
"2b69f2f8-d567-48c3-8bb3-22e0dc8819bd",
|
||||
"2b5267b2-ce87-4e77-ad88-5cfec80496b9",
|
||||
"483c3416-ddfb-43fe-983b-08abb6b50c62",
|
||||
"df9855d7-12ae-4170-acf6-a05cd4f52515",
|
||||
"1582d056-55fb-403b-8a65-f3b641c96b69",
|
||||
"be95bdcc-e72a-4132-8a67-9dde9bad5e2a",
|
||||
"299dd454-076d-4580-8cb9-4301997e86cd",
|
||||
"0a3412da-5f73-4738-8364-15d5919750f3",
|
||||
"197da27d-0497-40b5-b2f8-cec4124d32f6",
|
||||
"a031d9a8-e433-45cf-826a-8881644f8eac",
|
||||
"02702bf3-261c-41e0-a22d-26d3e90493a3",
|
||||
"a013fa2c-5b84-49d3-a3b4-fb80a768f37c",
|
||||
"c5ea5c83-9535-4d52-a2d0-12c101e3aee9",
|
||||
"672a0dd4-a5a0-43c1-bd40-f66cdb241ec7",
|
||||
"3b149bfe-31c5-4991-bd6c-ba4c760089d4",
|
||||
"b6ae5e37-db6a-4b79-949f-be73b216f677",
|
||||
"2f787b42-e43a-4cea-9c12-19a647e21eeb",
|
||||
"bfb708e4-18eb-47b5-afde-737f16721e9a",
|
||||
"f02032d3-3d60-4cb1-acac-855c229646c3",
|
||||
"96b24666-85f2-4f70-ae59-f5a924cc045f",
|
||||
"f7701275-cebc-482b-ac31-9cfcd93937c3",
|
||||
"fcfe4ee2-b247-4244-8cfc-f3d98d219fea",
|
||||
"c6b6d415-323e-46c1-859e-be86fd36ec48",
|
||||
"e53216bf-9815-42c7-89c1-953a7b1289a3",
|
||||
"5eeef2ff-1616-43bb-a0c1-aa84ad551824",
|
||||
"c78fffea-32b8-477e-81e9-7133119d9207",
|
||||
"59ccfdeb-8a8a-4693-b4fa-27034192071c",
|
||||
"849f1551-604a-4b5c-9b5d-e2771eed488c",
|
||||
"cf5d1920-9618-43f3-8dac-53954d19a956",
|
||||
"4d0bf08e-3dda-4a2e-8213-72a020873a03",
|
||||
"e48c8995-6a64-45c1-ae62-ba96fcc01542",
|
||||
"0ef5fdd2-718c-47d2-88bc-2d0193b18530",
|
||||
"8302b674-c728-42d2-9ba3-908b4d970436",
|
||||
"ab461de6-1137-4548-87bf-f9dd78905417",
|
||||
"0b26d479-d9a7-4e07-aa2f-4893467f41c2",
|
||||
"604dd8b8-175a-4a74-93d2-28760f1d1835",
|
||||
"26c5277c-440a-4dea-b625-beb986cff673",
|
||||
"8e33adf0-5932-4535-90c7-10fa04e97201",
|
||||
"1ef34494-4d48-4b69-9819-a22c5870fc24",
|
||||
"b2b8d7aa-06e8-4ed5-bc9b-cb9ce0e81309",
|
||||
"e4017ee0-6141-4145-816f-ed68ee6931bc",
|
||||
"84d32175-8cb8-4fb0-95cc-6ae13d40aaaa",
|
||||
"27489e34-b04c-410e-99a2-0d93e2e42fbf",
|
||||
"65cff7cb-0a29-4c0c-9280-76af55d1432d",
|
||||
"e5e8565f-80e2-4462-b687-56f6d64f95e4",
|
||||
"27accc37-c3fd-465f-99cd-3e131081aeca",
|
||||
"32e112bd-5495-4399-85dd-1925e1ccbba5",
|
||||
"dc50ca43-5071-45b3-bf42-e1e64416ffd0",
|
||||
"950a6345-5a13-4931-8d82-eac6adef03e3",
|
||||
"700640e7-0de3-49dc-b441-4efff8ad33ba",
|
||||
"5f35e542-a8cf-4422-8e87-466cdca62864",
|
||||
"f50cb362-2f86-44eb-89e6-bea6ecbaf89f",
|
||||
"31a7cbe0-6aa6-403b-a561-6bc4fa81c0b1",
|
||||
"d694804c-ae1a-4db0-b5fc-2497e43abb6f",
|
||||
"a008a4e6-e026-4a1c-8aef-eea78c41b029",
|
||||
"4575114c-1e63-41b1-8953-67d3ce3ed3e6",
|
||||
"853de4bd-6f6a-4d1d-980a-b67eb1b0e876",
|
||||
"cd0fa4e0-2d24-4b35-918a-33baa736015e",
|
||||
"933baf03-3664-4c33-bd97-208a9f7ab78b",
|
||||
"55bae3db-5f62-4be3-823a-bcb429b8a2b2",
|
||||
"4754b85b-e7a6-41a8-b0e9-5e02c58ebc38",
|
||||
"33f4fc73-102d-492e-9b0a-383d0b0f68b0",
|
||||
"fa8914be-0986-460c-884d-9973a9622045",
|
||||
"b9f734fa-de0d-4a0b-9ce2-c092126e1d8d",
|
||||
"448f3335-cf11-4e7a-9939-c734861d16e3",
|
||||
"106775db-a00d-4956-bf27-97ea269bb001",
|
||||
"594cd6c0-17db-4241-be56-ad28a8db4f7b",
|
||||
"95f7b67d-3ba8-4d18-bcbb-3e02f7bfaf7a",
|
||||
]
|
||||
KNOWLEDGEPROPS = "Anthology Academic Economics: Essential, Anthology Academic Economics: Enhanced, Anthology Accreditation: Essential, Anthology Accreditation: Enhanced, Anthology 101: Essential, Anthology Baseline: Essential, Anthology Baseline: Enhanced, Anthology Beacon: Essential, Anthology Course Evaluations: Essential, Anthology Course Evaluations: Enhanced, Anthology Digital Assistant: Essential, Anthology Digital Assistant: Enhanced, Anthology Encompass: Essential, Anthology Encompass: Enhanced, Anthology Encompass: Enhanced+, Anthology Engage: Essential, Anthology Engage: Enhanced, Anthology Engage: Enhanced+, Anthology Evaluate: Essential, Anthology Evaluate: Enhanced, Anthology Finance & HCM: Essential, Anthology Finance & HCM: Enhanced, Anthology Finance & HCM: Enhanced+, Anthology Insight: Essential, Anthology Insight: Enhanced, Blackboard Learn: Essential, Anthology Milestone: Essential, Anthology Milestone: Enhanced, Outcomes: Essential, Outcomes: Enhanced, Anthology Payroll: Essential, Anthology Payroll: Enhanced, Anthology Planning: Essential, Anthology Planning: Enhanced, Anthology Portfolio: Essential, Anthology Portfolio: Enhanced, Power BI: Essential, Power BI: Enhanced, Anthology Program Review: Essential, Anthology Program Review: Enhanced, Anthology Raise: Essential, Anthology Raise: Enhanced, Anthology Raise: Enhanced+, Anthology Reach: Essential, Anthology Reach: Enhanced, Anthology Reach: Enhanced+, Anthology Student: Essential, Anthology Student: Enhanced"
|
||||
|
||||
for row in df.itertuples():
|
||||
domain = row[1]
|
||||
groups = row[2:]
|
||||
# groups = list(groups)
|
||||
tmplist = []
|
||||
for group in groups:
|
||||
group = str(group)
|
||||
if "nan" not in group:
|
||||
# Grab Group UUIDs
|
||||
url = f"https://api.northpass.com/v2/groups?filter[name][eq]={group}"
|
||||
response = requests.get(url, headers=HEADERS)
|
||||
response = response.json()
|
||||
data = response["data"]
|
||||
for name in data:
|
||||
id = name["id"]
|
||||
tmplist.append(id)
|
||||
rowdict = {domain: tmplist}
|
||||
|
||||
# Grab all people
|
||||
personlist = []
|
||||
COUNT += 1
|
||||
url = BASEURL + f"?filter[email][cont]={domain}&limit=100"
|
||||
response = requests.get(url, headers=HEADERS)
|
||||
response = response.json()
|
||||
nextlink = response["links"]
|
||||
def groups():
|
||||
for row in df.itertuples():
|
||||
domain = row[1]
|
||||
groups = row[2:]
|
||||
# groups = list(groups)
|
||||
tmplist = []
|
||||
for group in groups:
|
||||
group = str(group)
|
||||
if "nan" not in group:
|
||||
# Grab Group UUIDs
|
||||
url = f"https://api.northpass.com/v2/groups?filter[name][eq]={group}"
|
||||
response = requests.get(url, headers=HEADERS)
|
||||
response = response.json()
|
||||
data = response["data"]
|
||||
for name in data:
|
||||
id = name["id"]
|
||||
tmplist.append(id)
|
||||
rowdict = {domain: tmplist}
|
||||
|
||||
for data in response["data"]:
|
||||
person = data["id"]
|
||||
personlist.append(person)
|
||||
# Grab all people
|
||||
personlist = []
|
||||
COUNT += 1
|
||||
url = BASEURL + f"?filter[email][cont]={domain}&limit=100"
|
||||
response = requests.get(url, headers=HEADERS)
|
||||
response = response.json()
|
||||
nextlink = response["links"]
|
||||
|
||||
# if "next" not in nextlink:
|
||||
# break
|
||||
for data in response["data"]:
|
||||
person = data["id"]
|
||||
personlist.append(person)
|
||||
|
||||
# Construct Payload for Bulk API
|
||||
payload = {"payload": {"person_ids": personlist, "group_ids": tmplist}}
|
||||
print(payload)
|
||||
# if "next" not in nextlink:
|
||||
# break
|
||||
|
||||
# Construct Payload for Bulk API
|
||||
payload = {"payload": {"person_ids": personlist, "group_ids": tmplist}}
|
||||
print(payload)
|
||||
|
||||
|
||||
def props():
|
||||
person_id_list = []
|
||||
count = 0
|
||||
while True:
|
||||
count += 1
|
||||
url = (
|
||||
BASEURL
|
||||
+ f"?filter[email][cont]=%40knowledgestate.edu&limit=100&page={count}"
|
||||
)
|
||||
response = requests.get(url, headers=HEADERS)
|
||||
response = response.json()
|
||||
nextlink = response["links"]
|
||||
|
||||
for data in response["data"]:
|
||||
person_name = data["attributes"]["name"]
|
||||
person = data["id"]
|
||||
print(f"Adding {person_name}'s id to list. ID: {person}")
|
||||
person_id_list.append(person)
|
||||
|
||||
if "next" not in nextlink:
|
||||
break
|
||||
|
||||
print(f"Cycling through {len(person_id_list)} people and adding their properties.")
|
||||
for person_id in person_id_list:
|
||||
propsurl = "https://api.northpass.com/v2/properties/people/bulk"
|
||||
payload = {
|
||||
"data": [
|
||||
{
|
||||
"attributes": {
|
||||
"properties": {"subscription_levels": KNOWLEDGEPROPS}
|
||||
},
|
||||
"id": person_id,
|
||||
"type": "person_properties",
|
||||
}
|
||||
]
|
||||
}
|
||||
prop_response = requests.post(propsurl, headers=HEADERS, json=payload)
|
||||
print(f"{person_id}'s status code is {prop_response.status_code}'")
|
||||
if prop_response.status_code != 200:
|
||||
print(
|
||||
f"There is a non-200 status code. The code was {prop_response.status_code}. Here's the text:"
|
||||
)
|
||||
print(f"{response.text}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
props()
|
||||
|
||||
BIN
Scripts/Sandata/Screenshot 2024-04-05 at 12.00.31 PM.png
Normal file
BIN
Scripts/Sandata/Screenshot 2024-04-05 at 12.00.31 PM.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 368 KiB |
203
Scripts/Sandata/clearUsers.js
Normal file
203
Scripts/Sandata/clearUsers.js
Normal file
@ -0,0 +1,203 @@
|
||||
const axios = require("axios")
|
||||
const fs = require("fs");
|
||||
const { parse } = require("csv-parse");
|
||||
// let xApiKey = 'XxDBlgH3CNSiD6yDgqZgpjjxB' //Austin SCHOOL API KEY
|
||||
let xApiKey = 'HdZFoXGCFpt8NnTOzIQY0kVDj' // <<< This is for sandata's school
|
||||
|
||||
let allNPUsers = [];
|
||||
let allUsers = [];
|
||||
|
||||
let getAllNPUsers = async (num) => {
|
||||
let page = num;
|
||||
console.log(`RETRIEVING PAGE ${num} OF USERS`)
|
||||
|
||||
await axios({
|
||||
method: 'get',
|
||||
// url: 'https://api.northpass.com/v2/people/?page=' + page + '&limit=100',
|
||||
url: 'https://api.northpass.com/v2/people/?page=' + page + '&limit=100',
|
||||
headers: {
|
||||
'accept': '*/*',
|
||||
'x-api-key': xApiKey,
|
||||
'content-type': 'application/json'
|
||||
}
|
||||
})
|
||||
.then(async (res) => {
|
||||
|
||||
if (res.data.links.next != null) {
|
||||
page++;
|
||||
for (let i = 0; i < res.data.data.length; i++) {
|
||||
allNPUsers.push(res.data.data[i]);
|
||||
}
|
||||
await getAllNPUsers(page);
|
||||
} else {
|
||||
for (let i = 0; i < res.data.data.length; i++) {
|
||||
allNPUsers.push(res.data.data[i]);
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
})
|
||||
}
|
||||
|
||||
// let getAllNPGroups = async (num) => {
|
||||
// let page = num;
|
||||
// console.log(`RETRIEVING PAGE ${num} OF GROUPS`)
|
||||
|
||||
// await axios({
|
||||
// method: 'get',
|
||||
// // url: 'https://api.northpass.com/v2/groups/?page=' + page + '&limit=100',
|
||||
// url: 'https://api.northpass.com/v2/groups/?page=' + page + '&limit=100',
|
||||
// headers: {
|
||||
// 'accept': '*/*',
|
||||
// 'x-api-key': xApiKey,
|
||||
// 'content-type': 'application/json'
|
||||
// }
|
||||
// })
|
||||
// .then(async (res) => {
|
||||
// // console.log(res.data.data)
|
||||
|
||||
// // console.log(res.data.links.next != null);
|
||||
// if (res.data.links.next != null) {
|
||||
// // console.log("not on last page")
|
||||
// page++;
|
||||
// for (let i = 0; i < res.data.data.length; i++) {
|
||||
// //console.log(res.data.data[i].attributes.name)
|
||||
// allNPGroups[res.data.data[i].attributes.name] = res.data.data[i].id
|
||||
// }
|
||||
// await getAllNPGroups(page);
|
||||
// } else {
|
||||
// //console.log("on last page")
|
||||
// for (let i = 0; i < res.data.data.length; i++) {
|
||||
// //console.log(res.data.data[i].attributes.name)
|
||||
// // allNPGroups[res.data.data[i].id] = res.data.data[i].attributes.name
|
||||
// allNPGroups[res.data.data[i].attributes.name] = res.data.data[i].id
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
// .catch(err => {
|
||||
// console.log(err);
|
||||
// })
|
||||
// };
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// CLEAR FUNCTIONS
|
||||
|
||||
const clearSchoolUsers = async (someArray, start) => {
|
||||
let iterator = start;
|
||||
let user = someArray[iterator];
|
||||
|
||||
// console.log(user.attributes.email)
|
||||
|
||||
if(allUsers.indexOf(user.attributes.email.toLowerCase()) > -1){
|
||||
// console.log('SHOULD BE CLEARED >>> ' + user.attributes.email)
|
||||
// console.log(user);
|
||||
await axios({
|
||||
method: "delete",
|
||||
// url: `https://api.northpass.com/v2/people/${user.id}`,
|
||||
url: `https://api.northpass.com/v2/people/${user.id}`,
|
||||
headers: {
|
||||
accept: "*/*",
|
||||
"x-api-key": xApiKey,
|
||||
"content-type": "application/json",
|
||||
},
|
||||
})
|
||||
.then(async () => {
|
||||
console.log(`TERMINATED USER WITH EMAIL: ${user.attributes.email}`)
|
||||
console.log('\x1b[36m%s\x1b[0m', `COMPLETED DELETING USER AT INDEX ${iterator}`);
|
||||
iterator += 1;
|
||||
|
||||
if(iterator >= someArray.length){
|
||||
return;
|
||||
} else {
|
||||
await clearSchoolUsers(someArray, iterator)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
iterator += 1;
|
||||
|
||||
if(iterator >= someArray.length){
|
||||
return;
|
||||
} else {
|
||||
await clearSchoolUsers(someArray, iterator)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// const clearSchoolGroups = async (someArray, start) => {
|
||||
// // console.log(someArray)
|
||||
// let iterator = start;
|
||||
// let groupName = someArray[iterator];
|
||||
|
||||
// let groupIDVal = allNPGroups[groupName];
|
||||
// if(groupName != 'PRIMARY ACCOUNT'){
|
||||
// await axios({
|
||||
// method: "delete",
|
||||
// // url: `https://api.northpass.com/v2/groups/${groupIDVal}`,
|
||||
// url: `https://api.northpass.com/v2/groups/${groupIDVal}`,
|
||||
// headers: {
|
||||
// accept: "*/*",
|
||||
// "x-api-key": xApiKey,
|
||||
// "content-type": "application/json",
|
||||
// },
|
||||
// })
|
||||
// .then(async () => {
|
||||
// console.log(`TERMINATED GROUP WITH UUID: ${groupIDVal}`)
|
||||
// console.log('\x1b[36m%s\x1b[0m', `COMPLETED DELETING GROUP AT INDEX ${iterator}`);
|
||||
// iterator += 1;
|
||||
|
||||
// if(iterator >= someArray.length){
|
||||
// return;
|
||||
// } else {
|
||||
// await clearSchoolGroups(someArray, iterator)
|
||||
// }
|
||||
// })
|
||||
// } else {
|
||||
// iterator += 1;
|
||||
|
||||
// if(iterator >= someArray.length){
|
||||
// return;
|
||||
// } else {
|
||||
// await clearSchoolGroups(someArray, iterator)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
let removeUsers = async () => {
|
||||
await getAllNPUsers(1)
|
||||
.then(async () => {
|
||||
await clearSchoolUsers(allNPUsers, 0);
|
||||
})
|
||||
}
|
||||
|
||||
// let removeGroups = async () => {
|
||||
// await getAllNPGroups(1)
|
||||
// .then(async () => {
|
||||
// // console.log(Object.keys(allNPGroups))
|
||||
// await clearSchoolGroups(Object.keys(allNPGroups), 0);
|
||||
// })
|
||||
// }
|
||||
|
||||
fs.createReadStream("./sandataPAusers.csv")
|
||||
.pipe(parse({ delimiter: ','}))
|
||||
.on("data", function (row) {
|
||||
|
||||
if(row[0] !== 'Email'){
|
||||
// allUsers.push({
|
||||
// email: row[0]
|
||||
// });
|
||||
allUsers.push(row[0].toLowerCase());
|
||||
}
|
||||
})
|
||||
.on("error", function (error) {
|
||||
console.log(error.message);
|
||||
})
|
||||
.on("end", async function () {
|
||||
console.log("FINISHED COLLECTING ALL NEW USERS");
|
||||
console.log(allUsers);
|
||||
console.log(allUsers.length);
|
||||
|
||||
// await executeFunctionChain();
|
||||
await removeUsers();
|
||||
})
|
||||
// removeGroups();
|
||||
66
Scripts/Sandata/import.js
Normal file
66
Scripts/Sandata/import.js
Normal file
@ -0,0 +1,66 @@
|
||||
const axios = require("axios")
|
||||
const fs = require("fs");
|
||||
const { parse } = require("csv-parse");
|
||||
//let xApiKey = "XxDBlgH3CNSiD6yDgqZgpjjxB" // <<< This is for Ausitn's School
|
||||
let xApiKey = 'HdZFoXGCFpt8NnTOzIQY0kVDj' // <<< This is for sandata's school
|
||||
|
||||
let allUsers = [];
|
||||
|
||||
fs.createReadStream("./sandataNevadaUsers.csv")
|
||||
.pipe(parse({ delimiter: ','}))
|
||||
.on("data", function (row) {
|
||||
|
||||
if(row[0] !== 'Email'){
|
||||
allUsers.push({
|
||||
email: row[0],
|
||||
group: 'ST - Nevada (DHCFP)'
|
||||
});
|
||||
}
|
||||
})
|
||||
.on("error", function (error) {
|
||||
console.log(error.message);
|
||||
})
|
||||
.on("end", async function () {
|
||||
console.log("FINISHED COLLECTING ALL NEW USERS");
|
||||
// console.log(allUsers[0]);
|
||||
console.log(allUsers.length);
|
||||
|
||||
await executeFunctionChain();
|
||||
})
|
||||
|
||||
|
||||
let executeFunctionChain = async () => {
|
||||
for(let i = 0; i < allUsers.length; i++){
|
||||
await axios({
|
||||
method: 'post',
|
||||
url: 'https://api.northpass.com/v2/bulk/people',
|
||||
data: {
|
||||
"data": {
|
||||
"attributes": {
|
||||
"people": [{
|
||||
"email": allUsers[i].email,
|
||||
// "email": "joojinhyung@gmail.com",
|
||||
"groups": allUsers[i].group
|
||||
//"groups": [10593ca2-daa7-41fb-ad12-1de77d51fe81] >> wrong, uses name not id
|
||||
}]
|
||||
}
|
||||
}
|
||||
},
|
||||
headers: {
|
||||
'accept': 'application/json',
|
||||
'x-api-key': xApiKey,
|
||||
'content-type': 'application/json'
|
||||
}
|
||||
})
|
||||
.then((res) => {
|
||||
console.log(`SUCCESSFULLY ADDED USER ${allUsers[i].email} TO GROUP ${allUsers[i].group}`)
|
||||
console.log(`COMPLETED USER ${i + 1}`)
|
||||
// console.log(res.data);
|
||||
return;
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err.data);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
193
Scripts/Sandata/properties.js
Normal file
193
Scripts/Sandata/properties.js
Normal file
@ -0,0 +1,193 @@
|
||||
const axios = require("axios")
|
||||
const fs = require("fs");
|
||||
const { parse } = require("csv-parse");
|
||||
//let xApiKey = "XxDBlgH3CNSiD6yDgqZgpjjxB" // <<< This is for Ausitn's School
|
||||
let xApiKey = 'HdZFoXGCFpt8NnTOzIQY0kVDj' // <<< This is for sandata's school
|
||||
|
||||
let allNPUsers = [];
|
||||
let allUsers = [];
|
||||
|
||||
let userExistsObj = {};
|
||||
|
||||
const getAllNPUsers = async (num) => {
|
||||
if(num === 1){
|
||||
console.log('\x1b[33m%s\x1b[0m', `RETRIEVING ALL NP USERS`);
|
||||
}
|
||||
console.log(`RETRIEVING PAGE ${num} OF USERS`)
|
||||
|
||||
|
||||
let page = num;
|
||||
await axios({
|
||||
method: 'get',
|
||||
url: 'https://api.northpass.com/v2/people/?page=' + page + '&limit=100',
|
||||
headers: {
|
||||
'accept': '*/*',
|
||||
'x-api-key': xApiKey,
|
||||
'content-type': 'application/json'
|
||||
}
|
||||
})
|
||||
.then(async (res) => {
|
||||
|
||||
if (res.data.links.next != null) {
|
||||
page++;
|
||||
for (let i = 0; i < res.data.data.length; i++) {
|
||||
allNPUsers.push(res.data.data[i]);
|
||||
}
|
||||
await getAllNPUsers(page);
|
||||
} else {
|
||||
for (let i = 0; i < res.data.data.length; i++) {
|
||||
allNPUsers.push(res.data.data[i]);
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
})
|
||||
}
|
||||
|
||||
const userExists = (userEmail) => {
|
||||
userEmail = userEmail.split('').map((letter) => letter.toLowerCase()).join('').trim();
|
||||
|
||||
let userExistsFlag = false;
|
||||
|
||||
for(let i = 0; i < allNPUsers.length; i++){
|
||||
if(allNPUsers[i].attributes.email == userEmail){
|
||||
userExistsFlag = true;
|
||||
|
||||
userExistsObj = {
|
||||
exists: true,
|
||||
data: allNPUsers[i]
|
||||
}
|
||||
return true;
|
||||
} else if(userExistsFlag === false && i === allNPUsers.length-1){
|
||||
userExistsObj = {
|
||||
exists: false,
|
||||
data: []
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fs.createReadStream("./sandataNevadaUsers.csv")
|
||||
.pipe(parse({ delimiter: ','}))
|
||||
.on("data", function (row) {
|
||||
|
||||
if(row[0] !== 'Email'){
|
||||
let user = {
|
||||
email: row[0]
|
||||
};
|
||||
|
||||
if(row[1].length > 0){
|
||||
user['agency_name'] = row[1];
|
||||
}
|
||||
if(row[2].length > 0){
|
||||
user['medicaid_id'] = row[2];
|
||||
}
|
||||
if(row[3].length > 0){
|
||||
user['provider_id'] = row[3];
|
||||
}
|
||||
// user['provider_id'] = '';
|
||||
if(row[4]){
|
||||
if(row[4].length > 0){
|
||||
user['agency_id'] = row[4];
|
||||
}
|
||||
}
|
||||
|
||||
allUsers.push(user);
|
||||
}
|
||||
})
|
||||
.on("error", function (error) {
|
||||
console.log(error.message);
|
||||
})
|
||||
.on("end", async function () {
|
||||
console.log("FINISHED COLLECTING ALL USERS");
|
||||
// console.log(allUsers);
|
||||
console.log(allUsers.length);
|
||||
|
||||
await executeFunctionChain();
|
||||
})
|
||||
|
||||
let executeFunctionChain = async () => {
|
||||
await getAllNPUsers(1)
|
||||
.then(async () => {
|
||||
console.log('\x1b[36m%s\x1b[0m', `COMPLETED IMPORTING ALL NP USERS`);
|
||||
console.log(allNPUsers.length);
|
||||
|
||||
let tracker = 0;
|
||||
|
||||
for(let i = 0; i < allUsers.length; i++){
|
||||
userExistsObj = {};
|
||||
let someUser = allUsers[i];
|
||||
|
||||
// console.log(someUser.email);
|
||||
|
||||
if(userExists(someUser.email)){
|
||||
// console.log('INDEX >>>>>>>>>>>>>>>>>>>>>>>>>>>>> ' + i)
|
||||
|
||||
let userID = userExistsObj.data.id;
|
||||
let propsObj = {};
|
||||
|
||||
if(someUser.agency_name){
|
||||
propsObj['agency_name'] = someUser.agency_name;
|
||||
}
|
||||
if(someUser.medicaid_id){
|
||||
propsObj['medicaid_id'] = someUser.medicaid_id;
|
||||
}
|
||||
if(someUser.provider_id){
|
||||
propsObj['provider_id'] = someUser.provider_id;
|
||||
}
|
||||
// else {
|
||||
// propsObj['provider_id'] = null;
|
||||
// }
|
||||
if(someUser.agency_id){
|
||||
propsObj['agency_id'] = someUser.agency_id;
|
||||
}
|
||||
propsObj['successfully_completed_secondary_registration'] = true;
|
||||
|
||||
tracker++;
|
||||
|
||||
await requestHandler(userID, propsObj)
|
||||
.then((res) => {
|
||||
console.log('\x1b[31m%s\x1b[0m', `SUCCESSFULLY SET PROPS FOR USER ${someUser.email} AT INDEX ${i}`);
|
||||
// console.log(`COMPLETED USER ${i + 1}`);
|
||||
// if(i == allUsers.length-1){
|
||||
// console.log(`${tracker} users updated`);
|
||||
// }
|
||||
return;
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch((err) => {console.log(err)})
|
||||
}
|
||||
|
||||
let requestHandler = async (userID, propsObj) => {
|
||||
// console.log(userID);
|
||||
console.log(propsObj);
|
||||
|
||||
await axios({
|
||||
method: "POST",
|
||||
url: "https://api.northpass.com/v2/properties/people/bulk",
|
||||
data: {
|
||||
data: [{
|
||||
id: userID,
|
||||
type:'person_properties',
|
||||
attributes: {
|
||||
'properties': propsObj
|
||||
},
|
||||
}],
|
||||
},
|
||||
headers: {
|
||||
'accept': 'application/json',
|
||||
'x-api-key': xApiKey,
|
||||
'content-type': 'application/json'
|
||||
}
|
||||
})
|
||||
// .catch((err) => {
|
||||
// console.log(err);
|
||||
// })
|
||||
}
|
||||
Reference in New Issue
Block a user