Argh, I haven't been at my home office and there was Cohesion this week, so I keep forgetting to push my changesgit status Todos, cleaned some dirs, and updated a script or too.

This commit is contained in:
Norm Rasmussen
2024-07-19 08:53:30 -04:00
parent dfeb4a8292
commit bf0244b2fe
7 changed files with 181 additions and 0 deletions

Binary file not shown.

View File

@ -0,0 +1,85 @@
const sheet = SpreadsheetApp.getActiveSheet();
const apiKey = '';
function getUuids() {
var sheet = SpreadsheetApp.getActiveSheet();
var numRows = sheet.getLastRow()-1; // Number of rows to process
var dataRange = sheet.getRange(3, 3, numRows, 1);
var values = dataRange.getValues();
writeHeadings();
for (email in values){
var row = values[email];
var email = row[0]
Logger.log(email)
var api_url = 'https://api.northpass.com/v2/people/?filter[email][eq]='+email;
const settings = {
async: true,
crossDomain: true,
method: 'GET',
headers: {
accept: 'application/json',
'X-Api-Key': apiKey
}
};
const sendMsg = UrlFetchApp.fetch(api_url, settings);
var uuidResponse = sendMsg.getContentText();
var parsedata = JSON.parse(uuidResponse);
Logger.log(parsedata)
try {
var uuid = parsedata["data"][0]["id"];
if (email != "") {
findRow(email, uuid);
}
}
catch(ex) {
Logger.log(ex)
continue
}
finally {
}
};
};
function findRow(email, uuid){
var sheetRow = SpreadsheetApp.getActiveSpreadsheet();
var data = sheetRow.getDataRange().getValues();
for(var i = 0; i<data.length;i++){
if(data[i][2] == email){ //[1] because column B
// Logger.log((i+1))
var row = i+1;
propstoSheet(uuid, row, email);
}
}
}
function propstoSheet(uuid, row, email) {
var uuid_url = 'https://api.northpass.com/v2/properties/people/'+uuid;
const settings = {
async: true,
crossDomain: true,
url: uuid_url,
method: 'GET',
headers: {
accept: 'application/json',
'X-Api-Key': apiKey,
}
};
const sendMsg = UrlFetchApp.fetch(uuid_url, settings);
var txtResponse = sendMsg.getContentText();
var parseProps = JSON.parse(txtResponse);
var agency_name = parseProps["data"]["attributes"]["properties"]["agency_name"];
if (agency_name == null ) {
var agency_name = "No Agency"
}
// Write the Data to each row and column
sheet.getRange(row, 16).setValue(agency_name);
// Logger.log(row + "," + email);
}
function writeHeadings() {
// Write the new Column Headings
sheet.getRange(1, 16).setValue("Agency Name");
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 362 KiB

View File

@ -0,0 +1 @@
ZENJOB = "LIXqtHXEqcXHyN0EtezngnpzA"

Binary file not shown.

View File

@ -0,0 +1,84 @@
import requests
import time
from playwright.sync_api import sync_playwright, Playwright
import pandas as pd
import Apikeys
IMPORTFILE = "~/Downloads/Internal Zenjob Testing group.csv"
APIKEY = Apikeys.ZENJOB
HEADERS = {"X-Api-Key": APIKEY, "accept": "application/json"}
ZENJOBURL = "https://zenjob.northpass.com/?uid="
BASEURL = "https://api.northpass.com/v2/"
def delete_people_first():
print("Deleting everyone with a zenjob email address...")
count = 0
delete_list = []
while True:
count += 1
person_url = f"{BASEURL}people?filter[sso_uid][cont]=zenjob.com&filter[partnerships_type][not_eq]=Partnerships::Admin&include=partnerships&page={count}"
person_resp = requests.get(person_url, headers=HEADERS)
persjson = person_resp.json()
nextlink = persjson["links"]
for people in persjson["data"]:
learneruuid = people["id"]
delete_list.append(learneruuid)
if "next" not in nextlink:
break
del_load = {"payload": delete_list}
print(len(delete_list))
# del_url = f"{BASEURL}bulk/people/delete"
print("Running Post Func for Deleting Users")
# post_func(del_url, del_load)
def run(playwright: Playwright):
df = pd.read_csv(IMPORTFILE)
emails = df["Work Email"].values.tolist()
# for email in emails:
# webkit = playwright.webkit
# browser = webkit.launch()
# context = browser.new_context()
# page = context.new_page()
# # page.goto(f"{BASEURL}{email}")
# print(f"{ZENJOBURL}{email}")
# context.close()
add_ppl_to_groups(emails)
def add_ppl_to_groups(emails):
print("Assuming everyone was created with playwright, now I'm going to add everyone to the group.")
learner_list = []
for person in emails:
get_person_url = f"{BASEURL}people?filter[email][eq]={person}"
get_person_resp = requests.get(get_person_url, headers=HEADERS)
person_json = get_person_resp.json()
learner_uuid = person_json["data"][0]["id"]
learner_list.append(learner_uuid)
bulk_to_groups_url = f"{BASEURL}bulk/people/membership"
bulk_payload = {"payload": {"person_ids": learner_list, "group_ids": ["940a5d24-32af-45f1-8ed4-8a6b4689d9c9"]}}
print("Running Post Func for Bulk Add to Groups")
# post_func(bulk_to_groups_url, bulk_payload)
def post_func(url, payload):
try:
req = requests.post(url, headers=HEADERS, json=payload)
except (HTTPError, ExceptionError) as e:
print(e)
finally:
print(req.status_code)
print(req.text)
if __name__ == "__main__":
delete_people_first()
time.sleep(5)
print("Sleeping to allow deletions to process.")
with sync_playwright() as playwright:
run(playwright)

View File

@ -368,3 +368,14 @@ message](https://northpasshq.slack.com/archives/C04RER4PH09/p1709147957374999?th
## 07-15-2024
- [ ] MATTR - Create ticket spreadsheet to share with client.
## 07-17-2024
- [ ] Chubb - Send Steve Google App Script & ask Kim what report she needs
- [ ] Chubb - Ask SE for Delivery Log export from db. They are trying to find the best way to reminder agents who haven't started anything to actually start the path. Include all the data.
- [ ] Volt - They would like an Archive Webhook. "It's necessary for the whole equation of getting everything up to enterprise level standards." No rush but it would help fill in the whole circle.
- [X] HH - Looker: Course Completion, only yes, last 24 hours, scheduled for "results are changed" and 8am every day.
## 07-18-2024
- [ ] Cin7 - Check this: can a not-activated user in prereg sign up on the sign up page?