Started the reorganization of Scripts for github. Some notes changes.
This commit is contained in:
@ -4,8 +4,8 @@ from pathlib import Path
|
||||
import Apikeys
|
||||
import os
|
||||
|
||||
basefile = "/Users/normrasmussen/Downloads/mizuno-monthly-completions.csv"
|
||||
api_key = Apikeys.mizuno
|
||||
basefile = "/Users/normrasmussen/Downloads/Recast-learners.csv"
|
||||
api_key = Apikeys.recast
|
||||
uuid_url = "https://api.northpass.com/v2/people?filter[email][eq]="
|
||||
prop_url = "https://api.northpass.com/v2/properties/people/"
|
||||
headers = {
|
||||
@ -30,16 +30,12 @@ def load_file(basefile):
|
||||
response = requests.get(url, headers=headers)
|
||||
if response.status_code == 200:
|
||||
response = response.json()
|
||||
print(response)
|
||||
uuid = response["data"][0]["id"]
|
||||
print(uuid)
|
||||
url2 = prop_url + f"{uuid}"
|
||||
response = requests.get(url2, headers=headers)
|
||||
data = response.json()
|
||||
pgaid = data["data"]["attributes"]["properties"]["account_number"]
|
||||
row_dict["pgaid"] = pgaid
|
||||
elif response.status_code == 404:
|
||||
row_dict["pgaid"] = "User Not Found"
|
||||
dict_list.append(row_dict)
|
||||
print("No errors! Passing along the dictionary!")
|
||||
except KeyError as e:
|
||||
|
||||
@ -2,8 +2,8 @@ import requests
|
||||
import pandas as pd
|
||||
import Apikeys
|
||||
|
||||
csv = "/Users/normrasmussen/Downloads/Recast-learners.csv"
|
||||
apiKey = Apikeys.skuid
|
||||
csv = "/Users/normrasmussen/Downloads/client-learners.csv"
|
||||
apiKey = Apikeys.client
|
||||
baseUrlemail = "https://api.northpass.com/v2/people?filter[email][eq]="
|
||||
|
||||
|
||||
@ -37,11 +37,8 @@ def getfromEmail(emails, baseUrlemail, apiKey, data):
|
||||
else:
|
||||
print("Another Error!")
|
||||
|
||||
# print(email_ids)
|
||||
data["uuid"] = data["email"].map(email_ids)
|
||||
data.dropna(how='any', inplace=True)
|
||||
# print(data)
|
||||
# print(errors)
|
||||
assignProps(data, apiKey)
|
||||
errorstoCsv(errors)
|
||||
|
||||
@ -49,7 +46,7 @@ def getfromEmail(emails, baseUrlemail, apiKey, data):
|
||||
def errorstoCsv(errors):
|
||||
errorcsv = pd.DataFrame(errors)
|
||||
errorcsv.to_csv(
|
||||
path_or_buf="/Users/normrasmussen/Downloads/Talkspace_Emails_Not_Northpass.csv",
|
||||
path_or_buf="/Users/normrasmussen/Downloads/Emails_Not_Northpass.csv",
|
||||
index=False
|
||||
)
|
||||
|
||||
|
||||
@ -4,8 +4,8 @@ from pathlib import Path
|
||||
import Apikeys
|
||||
import os
|
||||
|
||||
basefile = "/Users/normrasmussen/Downloads/Recast-learners.csv"
|
||||
api_key = Apikeys.recast
|
||||
basefile = "/Users/normrasmussen/Downloads/client-learners.csv"
|
||||
api_key = Apikeys.client
|
||||
prop_url = "https://api.northpass.com/v2/properties/people/"
|
||||
headers = {
|
||||
"accept": "*/*",
|
||||
@ -45,7 +45,7 @@ def load_file(basefile):
|
||||
completions.loc[completions.index[row], "Company"] = comp
|
||||
print(completions)
|
||||
completions.to_csv(
|
||||
"/Users/normrasmussen/Downloads/Recast_learners_w_Company.csv",
|
||||
"/Users/normrasmussen/Downloads/client_learners_w_Company.csv",
|
||||
index=False
|
||||
)
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import requests
|
||||
import Apikeys
|
||||
|
||||
apiKey = "84GO7zb7a990UJrnFJqiYcd0m"
|
||||
# Skuid's API
|
||||
apiKey = Apikeys.client
|
||||
|
||||
|
||||
def getallUuid(apiKey):
|
||||
|
||||
86
Scripts/API_Tests/addgroup_users.py
Normal file
86
Scripts/API_Tests/addgroup_users.py
Normal file
@ -0,0 +1,86 @@
|
||||
import requests
|
||||
import sys
|
||||
import pandas as pd
|
||||
import Apikeys
|
||||
|
||||
# Enter your API Key between the quotation marks.
|
||||
apiKey = ""
|
||||
groupName = sys.argv[1]
|
||||
peopleCsv = "/path/to/file/peopletogroups.csv"
|
||||
|
||||
|
||||
def createGroup(groupName, apiKey):
|
||||
# apiKey = input("What is your API Key? ")
|
||||
# Create a Group endpoint - params: group_uuid
|
||||
url = "https://api.northpass.com/v2/groups"
|
||||
payload = {"data": {"attributes": {"name": f"{groupName}"}}}
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
"content-type": "application/json",
|
||||
"X-Api-Key": apiKey,
|
||||
}
|
||||
groupresponse = requests.post(url, json=payload, headers=headers)
|
||||
if "already have a group with this name" in groupresponse.text:
|
||||
groupName = input("Group already created, what name would you like instead? ")
|
||||
print("Got it, thanks! Attempting to create the group now.")
|
||||
createGroup(groupName, apiKey)
|
||||
else:
|
||||
readCSV(apiKey, groupresponse)
|
||||
|
||||
|
||||
def readCSV(apiKey, groupresponse):
|
||||
people = []
|
||||
readExport = pd.read_csv(
|
||||
peopleCsv,
|
||||
usecols=["UUID"],
|
||||
skipinitialspace=True,
|
||||
)
|
||||
people.extend(readExport["UUID"].tolist())
|
||||
getgroupId(people, groupresponse, apiKey)
|
||||
|
||||
|
||||
def getgroupId(people, groupresponse, apiKey):
|
||||
groupresponse = groupresponse.json()
|
||||
groupID = groupresponse["data"]["id"]
|
||||
ppltoGroup(people, groupID, apiKey)
|
||||
|
||||
|
||||
def ppltoGroup(people, groupID, apiKey):
|
||||
for uuid in people:
|
||||
payload = {
|
||||
"data": [
|
||||
{"type": "people", "id": uuid},
|
||||
]
|
||||
}
|
||||
# Add People to a Group. Params needed: group_uuid
|
||||
url = f"https://api.northpass.com/v2/groups/{groupID}/relationships/people"
|
||||
headers = {
|
||||
"accept": "*/*",
|
||||
"content-type": "application/json",
|
||||
"X-Api-Key": apiKey,
|
||||
}
|
||||
response = requests.post(url, json=payload, headers=headers)
|
||||
if "404" in response.text:
|
||||
print("Error returned for this user. Collecting names.")
|
||||
errorNames(apiKey, uuid)
|
||||
else:
|
||||
pass
|
||||
|
||||
|
||||
def errorNames(apiKey, uuid):
|
||||
url = f"https://api.northpass.com/v2/people/{uuid}"
|
||||
headers = {"accept": "application/json", "X-Api-Key": apiKey}
|
||||
response = requests.get(url, headers=headers)
|
||||
response = response.json()
|
||||
errorList = []
|
||||
names = response["data"]["attributes"]["full_name"]
|
||||
errorList.append(names)
|
||||
fullNames(errorList)
|
||||
|
||||
|
||||
def fullNames(errorList):
|
||||
print(errorList)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
createGroup(groupName, apiKey)
|
||||
@ -1,13 +1,12 @@
|
||||
import requests
|
||||
import pandas as pd
|
||||
import Apikeys
|
||||
|
||||
baseCsv = "/Users/normrasmussen/Downloads/Incomplete list for NP monthly communcation 12.19.22 - Users.csv"
|
||||
baseCsv = "/Users/normrasmussen/Downloads/Incomplete list of Users.csv"
|
||||
baseUrl = "https://api.northpass.com/v2/people/"
|
||||
baseUrlname = "https://api.northpass.com/v2/people?filter[name][eq]="
|
||||
baseUrlemail = "https://api.northpass.com/v2/people?filter[email][eq]="
|
||||
# apiKey = "JRDpCGQ7vSRiva6t5OkWDr5eJ" # G2
|
||||
# apiKey = "6hUfJdAartHTHhHc0WIRZYPWe" #Walmart
|
||||
apiKey = "84GO7zb7a990UJrnFJqiYcd0m" # Skuid's API
|
||||
apikey = Apikeys.client
|
||||
|
||||
|
||||
def getfromEmail(baseUrlemail, baseCsv, apiKey):
|
||||
|
||||
77
Scripts/API_Tests/api_extracts.py
Normal file
77
Scripts/API_Tests/api_extracts.py
Normal file
@ -0,0 +1,77 @@
|
||||
import requests
|
||||
import subprocess
|
||||
import gzip
|
||||
import urllib.request
|
||||
import base64
|
||||
|
||||
# Variables of the needed elements
|
||||
extract_id = "506c7250-2365-456d-be91-b1e146a398fe"
|
||||
auth_token = "g5k8QpUlePaL5UFSz9Kob4nbYHIyEH0W2lhtbrDu"
|
||||
base_url = "https://analytics.northpass.io/extracts"
|
||||
encryption_key = "ba6iy6jPmTxlIs73f+7FcXC8FDXt98mW46WbmKpLPsY="
|
||||
current_dir = "./"
|
||||
|
||||
# Set the API endpoint, authentication headers, and other parameters
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
"X-Api-Key": "g5k8QpUlePaL5UFSz9Kob4nbYHIyEH0W2lhtbrDu",
|
||||
}
|
||||
|
||||
|
||||
# This first call provides you with the fileID and IV value to download the encrypted file
|
||||
def get_extract_id(base_url, headers, extract_id, encryption_key):
|
||||
url = f"{base_url}/{extract_id}/files/latest/"
|
||||
response = requests.get(url, headers=headers)
|
||||
data = response.json()
|
||||
file_id = data["fileId"]
|
||||
iv = data["initializationVector"]
|
||||
download_file(base_url, headers, extract_id, file_id, encryption_key, iv)
|
||||
|
||||
|
||||
# This function downloads the file, changes the IV and EK from base64 to Hex, and then decrypts it.
|
||||
# It then opens and prints the results for verification that the data is human readable.
|
||||
def download_file(base_url, headers, extract_id, file_id, encryption_key, iv):
|
||||
url = f"{base_url}/{extract_id}/files/{file_id}/download"
|
||||
response = requests.get(url, headers=headers)
|
||||
data = response.json()
|
||||
download_url = data["url"]
|
||||
|
||||
# Downloads the file to the cwd
|
||||
url_resp = urllib.request.urlretrieve(download_url, "UXDesign_API_Extract.csv.gz")
|
||||
file_name = url_resp[0]
|
||||
decrypted_file = "UXDesign_Accessible.csv.gz"
|
||||
|
||||
# Base64 > Hex
|
||||
encryption_key = base64.b64decode(encryption_key).hex()
|
||||
print(encryption_key)
|
||||
iv = base64.b64decode(iv).hex()
|
||||
print(iv)
|
||||
|
||||
# Decryption Command as provided in Northpass Documentation
|
||||
resp = subprocess.run(
|
||||
[
|
||||
"openssl",
|
||||
"enc",
|
||||
"-aes-256-cbc",
|
||||
"-d",
|
||||
"-nosalt",
|
||||
"-in",
|
||||
file_name,
|
||||
"-out",
|
||||
decrypted_file,
|
||||
"-K",
|
||||
encryption_key,
|
||||
"-iv",
|
||||
iv,
|
||||
]
|
||||
)
|
||||
print(resp)
|
||||
|
||||
# Print data in CSV to ensure it is human readable
|
||||
with gzip.open(decrypted_file, "rb") as uncompressed:
|
||||
file = uncompressed.read()
|
||||
print(file)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
get_extract_id(base_url, headers, extract_id, encryption_key)
|
||||
@ -3,6 +3,10 @@ import requests
|
||||
import Apikeys
|
||||
|
||||
|
||||
'''
|
||||
This file is mostly used for random testing of unknown endpoints, like our V1 endpoints.
|
||||
'''
|
||||
|
||||
# url ="https://api.northpass.com/v2/groups/e6ef3e5f-b5a2-4b10-868b-8c165d76d263/learning_paths"
|
||||
# url = "https://api.northpass.com/v1/media?limit=1"
|
||||
# url = "https://api.northpass.com/v1/learning_paths"
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import requests
|
||||
import Apikeys
|
||||
|
||||
apiKey = "Bknf8kidbluRfcKu3m3lKoxS8"
|
||||
apiKey = Apikeys.client
|
||||
groups = [
|
||||
"Armonk",
|
||||
"Babylon",
|
||||
|
||||
@ -24,7 +24,7 @@ for group in groups_to_create:
|
||||
payload2.append({"name": group})
|
||||
payload = {"data": {"attributes": {"groups": payload2}}}
|
||||
|
||||
# print(payload)
|
||||
response = requests.post(url, json=payload, headers=headers)
|
||||
print(response.text)
|
||||
print(response)
|
||||
print(payload)
|
||||
# response = requests.post(url, json=payload, headers=headers)
|
||||
# print(response.text)
|
||||
# print(response)
|
||||
|
||||
76
Scripts/API_Tests/find_completed.py
Normal file
76
Scripts/API_Tests/find_completed.py
Normal file
@ -0,0 +1,76 @@
|
||||
from collections import Counter
|
||||
import pandas as pd
|
||||
|
||||
basecsv = "/Users/normrasmussen/Documents/Northpass/Scripts/Skuid_LPs/Skuid_MCA125.csv"
|
||||
lpcsv = "/Users/normrasmussen/Documents/Northpass/Scripts/Skuid_LPs/skuidlps.csv"
|
||||
|
||||
"""
|
||||
Example multivalue dictionary
|
||||
|
||||
dict = {key1: [value1, value2, value3, value4],
|
||||
key2: [value5, value6, value 7],
|
||||
}
|
||||
|
||||
So this could be used for each learning path. In other words:
|
||||
|
||||
learning_paths = {'01:Skuid Ethos' : ["Congratulations", "Create", "Skuid Resources"]} etc etc
|
||||
|
||||
Ideally, we will add Alexa's "levels" in this dictionary as well. Could we do:
|
||||
|
||||
learning_paths = {'Level_1': [{'01:Skuid Ethos' : ["Congratulations", "Create", "Skuid Resources"]},
|
||||
{'02:Composer' : ["Overview", "Get Started with Composer", "Manage Pages"}]
|
||||
{'03:Design System Studio' : ["Get Started with Design Systems", etc etc]},
|
||||
'Level_2': [{'10 - Data' : ["Tips to Optimize", "Smarter Conditions"]},
|
||||
{'11-Components': ["Battle", "Engage"]},
|
||||
]
|
||||
}
|
||||
|
||||
How to create this by automation?
|
||||
"""
|
||||
|
||||
|
||||
def lpLevels(basecsv, lpcsv):
|
||||
levels = pd.read_csv(
|
||||
lpcsv,
|
||||
index_col=1,
|
||||
)
|
||||
newDf = levels.groupby("Learning Path")
|
||||
newDf2 = newDf.apply(lambda x: x["Course Name"].unique())
|
||||
learningpaths = newDf2.apply(pd.Series)
|
||||
learningpaths.rename_axis(index=0)
|
||||
mainFunc(basecsv, learningpaths)
|
||||
# print(levels.Level.unique()) # Print only unique values from the Level column
|
||||
|
||||
|
||||
def mainFunc(basecsv, learningpaths):
|
||||
# Part 1
|
||||
readData = pd.read_csv(
|
||||
basecsv,
|
||||
)
|
||||
group = readData.groupby("Learner Full Name")
|
||||
df2 = group.apply(lambda x: x["Course Name"].unique())
|
||||
df2 = df2.apply(pd.Series, dtype="string")
|
||||
# print(df2)
|
||||
# This prints a dataframe with the learner's name as the index column and the courses as adjacent columns
|
||||
|
||||
# Part 2
|
||||
courses = learningpaths.set_index(0)
|
||||
# print(courses)
|
||||
# lp_dict = learningpaths.to_dict("index")
|
||||
# courses = lp_dict.values()
|
||||
# Part 3
|
||||
print(df2.isin(df2))
|
||||
# This produces a bunch of T/F in the dataframe. Is the solution to do:
|
||||
# for courses in lp_dict, for row(person) in readData
|
||||
# if number of True == length/# of values in courses
|
||||
# Add to "Finished List"
|
||||
|
||||
# df3 = df2.columns
|
||||
# print(df3)
|
||||
# for name in df3.items():
|
||||
# print(f"name: {name}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# mainFunc(basecsv)
|
||||
lpLevels(basecsv, lpcsv)
|
||||
28
Scripts/API_Tests/fix_unenroll.py
Normal file
28
Scripts/API_Tests/fix_unenroll.py
Normal file
@ -0,0 +1,28 @@
|
||||
from collections import Counter
|
||||
import pandas as pd
|
||||
|
||||
basecsv = "/Users/normrasmussen/Documents/Northpass/Scripts/G2_Unenroll/skuid_05lp.csv"
|
||||
|
||||
def mainFunc(basecsv):
|
||||
readData = pd.read_csv(
|
||||
basecsv,
|
||||
index_col=False,
|
||||
)
|
||||
parsedData = readData.drop_duplicates(subset='Course_Name', keep="first")
|
||||
if parsedData.loc[readData['Course Name'].isin([
|
||||
'Get Started with Models - Level 1',
|
||||
'Configure Model Fields - Level 1',
|
||||
'Configure Model Conditions - Level 1',
|
||||
'Configure Model Actions - Level 1',
|
||||
'Manage Models - Level 1',
|
||||
'Intro to UI Only Fields - Level 1'])]:
|
||||
extractedList = readData.loc[readData['Email'].tolist()
|
||||
fourOccs = Counter(extractedList)
|
||||
finalNames = []
|
||||
for name, occurences in fourOccs.items():
|
||||
if occurences == 6:
|
||||
finalNames.append(name)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
mainFunc(basecsv)
|
||||
59
Scripts/API_Tests/manual_lps.py
Normal file
59
Scripts/API_Tests/manual_lps.py
Normal file
@ -0,0 +1,59 @@
|
||||
from collections import Counter
|
||||
import pandas as pd
|
||||
import glob
|
||||
import re
|
||||
|
||||
basecsv = "/Users/normrasmussen/Documents/Northpass/Scripts/Skuid_LPs/Skuid_MCA125.csv"
|
||||
directory = "/Users/normrasmussen/Documents/Northpass/Scripts/Skuid_LPs/LPCSVs/*.csv"
|
||||
lpcsv = "/Users/normrasmussen/Documents/Northpass/Scripts/Skuid_LPs/skuidlps.csv"
|
||||
|
||||
# Unfortunately, what this needs is a CSV per learning path/MCA export. That will be painful to run.
|
||||
|
||||
|
||||
def manualFunc(lpcsv, directory):
|
||||
lps = pd.read_csv(lpcsv)
|
||||
lpcourses = lps.groupby(["Learning Path"])["Course Name"]
|
||||
coursenums = lpcourses.nunique()
|
||||
coursenums = coursenums.to_dict()
|
||||
lpnames = coursenums.keys()
|
||||
# print(lpnames)
|
||||
# num = re.match(r"(\d{2})")
|
||||
# for row in coursenums:
|
||||
# print(row)
|
||||
# print(coursenums.keys())
|
||||
# keys() and values() will show the respective columns. Adding the full LP string will show the values.
|
||||
# What if... I do something like
|
||||
# The next step is to compare each of the items in this list with the results of each fname. I wonder if I can do it by regex?
|
||||
lp_dict = {}
|
||||
lp_list = []
|
||||
for fname in glob.glob(directory):
|
||||
readData = pd.read_csv(
|
||||
fname,
|
||||
)
|
||||
emailGroups = readData.groupby(["Email", "Learner Full Name"])[
|
||||
"Course Name"
|
||||
].nunique()
|
||||
peoples = emailGroups.to_dict()
|
||||
num = re.findall(r"(\d{2})", fname)
|
||||
for lp, nums in coursenums.items():
|
||||
file_num = str(num[0])
|
||||
file_num = f"{file_num:02}"
|
||||
lp_num = re.findall(r"(\d{2})", lp)
|
||||
lp_num = str(lp_num[0])
|
||||
if file_num == lp_num:
|
||||
lp_list = []
|
||||
# print(file_num+"+"+lp_num)
|
||||
for person, completions in peoples.items():
|
||||
if completions == nums:
|
||||
lp_list.append(person)
|
||||
ppl_todict = {fname: lp_list}
|
||||
lp_dict.update(ppl_todict)
|
||||
|
||||
final = pd.DataFrame({key: pd.Series(value) for key, value in lp_dict.items()})
|
||||
final.to_csv(
|
||||
"/Users/normrasmussen/Documents/Northpass/Scripts/Skuid_LPs/finaltest3.csv"
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
manualFunc(lpcsv, directory)
|
||||
54
Scripts/API_Tests/usercomparison.py
Normal file
54
Scripts/API_Tests/usercomparison.py
Normal file
@ -0,0 +1,54 @@
|
||||
import csv
|
||||
from Levenshtein import distance as lev
|
||||
import pandas as pd
|
||||
import itertools
|
||||
import sys
|
||||
|
||||
peopleCsv = "/Users/normrasmussen/Downloads/TalkspaceAllLearners.csv"
|
||||
|
||||
|
||||
def readCsv(peopleCsv):
|
||||
people = []
|
||||
readExport = pd.read_csv(
|
||||
peopleCsv,
|
||||
usecols=["Learner Full Name", "Email"],
|
||||
skipinitialspace=True,
|
||||
# index_col=True,
|
||||
)
|
||||
people.extend(readExport["Email"].tolist())
|
||||
startCompare(peopleCsv, people, readExport)
|
||||
|
||||
|
||||
# itertools combinations
|
||||
def startCompare(peopleCsv, people, readExport):
|
||||
email1 = []
|
||||
email2 = []
|
||||
for (
|
||||
name1,
|
||||
name2,
|
||||
) in itertools.combinations(people, 2):
|
||||
# print(name1, name2) - prints all pairs, working so far.
|
||||
distance = lev(name1, name2)
|
||||
# print(distance) - successfully returns numbers
|
||||
if distance > 0 and distance < 2:
|
||||
email1.append(name1)
|
||||
email2.append(name2)
|
||||
writenewColumn(email1, email2, peopleCsv, readExport)
|
||||
|
||||
|
||||
def writenewColumn(email1, email2, peopleCsv, readExport):
|
||||
df = pd.DataFrame(readExport)
|
||||
print(df)
|
||||
df["Email1"] = pd.Series(email1)
|
||||
df["Email2"] = pd.Series(email2)
|
||||
df.drop_duplicates("Email1", inplace=True)
|
||||
df.drop_duplicates("Email2", inplace=True)
|
||||
df.drop_duplicates(subset=["Email1", "Email2"])
|
||||
# keep = 'last').reset_index(drop=True)
|
||||
writeLst = df.to_csv(
|
||||
"/Users/normrasmussen/Downloads/TalkspaceDupes_singlechange.csv",
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
readCsv(peopleCsv)
|
||||
Reference in New Issue
Block a user