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()
|
||||
@ -100,6 +100,7 @@ function updatedDomainsOnly(domains_to_update) {
|
||||
var corrList = [];
|
||||
for (var x = 0; x < domains_to_update.length; x++) {
|
||||
var array = domains_to_update[x];
|
||||
Logger.log(array)
|
||||
var currDomain = domains_to_update[x][0]
|
||||
var errorObj = new Object();
|
||||
var noErrorObj = new Object();
|
||||
@ -109,7 +110,6 @@ function updatedDomainsOnly(domains_to_update) {
|
||||
for (var i = 1; i < array.length; i++) {
|
||||
var item = array[i]
|
||||
if (item != "") {
|
||||
Logger.log("Item/Domain: "+item)
|
||||
var api_url = 'https://api.northpass.com/v2/groups/?filter[name][eq]='+encodeURIComponent(item);
|
||||
const settings = {
|
||||
async: true,
|
||||
@ -123,15 +123,16 @@ function updatedDomainsOnly(domains_to_update) {
|
||||
const sendMsg = UrlFetchApp.fetch(api_url, settings);
|
||||
var uuidResponse = sendMsg.getContentText();
|
||||
var parseData = JSON.parse(uuidResponse);
|
||||
var groupName = array.indexOf(item);
|
||||
if (parseData['data'].length >= 1) {
|
||||
var groupID = parseData['data'][0]['id'];
|
||||
var groupName = array.indexOf(item);
|
||||
if (groupName != -1) {
|
||||
array[groupName] = groupID;
|
||||
}
|
||||
}
|
||||
correctGroups.push(item)
|
||||
} else {
|
||||
errorGroups.push(item);
|
||||
array[groupName] = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -146,9 +147,9 @@ function updatedDomainsOnly(domains_to_update) {
|
||||
sendWebhook({domain_to_update : { domain: dom, group_ids: groups }})
|
||||
replaceOnSheet(dom, groups);
|
||||
}
|
||||
MailApp.sendEmail("nrasmussen@gainsight.com",
|
||||
"Anthology has submitted a CSV",
|
||||
"Here are the domains that will be updated: "+JSON.stringify(noErrorObj)+"\n\n"+"Group Errors (they likely don't exist): "+JSON.stringify(errorList));
|
||||
// MailApp.sendEmail("nrasmussen@gainsight.com",
|
||||
// "Anthology has submitted a CSV",
|
||||
// "Here are the domains that will be updated: "+JSON.stringify(noErrorObj)+"\n\n"+"Group Errors (they likely don't exist): "+JSON.stringify(errorList));
|
||||
MailApp.sendEmail("amitd@anthology.com",
|
||||
"Anthology has submitted a CSV",
|
||||
"Here are the domains that will be updated: "+JSON.stringify(noErrorObj)+"\n\n"+"Group Errors (they likely don't exist): "+JSON.stringify(errorList));
|
||||
|
||||
Reference in New Issue
Block a user