G2 Script Completed

This commit is contained in:
Norm Rasmussen
2022-11-21 16:08:13 -05:00
parent 53cb80e773
commit d54f1e926a
7 changed files with 2114 additions and 59 deletions

View File

@ -1,13 +1,13 @@
import requests
import urllib.parse
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
def getfromName(baseUrlname, apiKey):
name = "Norm Test Testing Norm"
name = "Someone else"
url = baseUrlname + f"{name}"
headers = {
"accept": "*/*",
@ -15,15 +15,19 @@ def getfromName(baseUrlname, apiKey):
"content-type": "application/json",
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
print("200 Response!")
else:
print("Another error! " + response.status_code)
response = response.json()
print(response)
uuid = response["data"][0]["id"]
print("Learner ID:" )
print(uuid)
#print(response)
#uuid = response["data"][0]["id"]
#print("Learner ID:" )
#print(uuid)
def getfromEmail(baseUrlemail, apiKey):
email = "norm%2Bg2test@northpass.com" # The %2B encodes the + sign in the URL. Using the + sign won't work.
#email = "aaron.rodgers@corpay.com"
#email = "norm2test@northpass.com" # The %2B encodes the + sign in the URL. Using the + sign won't work.
email = " "
url = baseUrlemail + f"{email}"
print(url)
headers = {
@ -32,12 +36,30 @@ def getfromEmail(baseUrlemail, apiKey):
"content-type": "application/json",
}
response = requests.get(url, headers=headers)
response = response.json()
print(response)
if response.status_code == 200:
print("200 Error!")
else:
print("Another Error!")
response = response.json()
#print(response)
uuid = response["data"]
print("Learner ID:" )
print(uuid)
#print("Learner ID:" )
#print(uuid)
def getfromUuid(baseUrl, apiKey):
uuid = "57b2b5eb-aa56-4cee-bb32-8c678a2de1b7"
url = baseUrl + uuid
headers = {
"accept": "*/*",
"x-api-key": apiKey,
"content-type": "application/json",
}
response = requests.get(url, headers=headers)
print(response.status_code)
print(response.text)
if __name__ == "__main__":
getfromEmail(baseUrlemail, apiKey)
getfromUuid(baseUrl, apiKey)
#getfromEmail(baseUrlemail, apiKey)
#getfromName(baseUrlname, apiKey)

View File

@ -1,42 +1,81 @@
import requests
import os
from datetime import date
from collections import Counter
import pandas as pd
basecsv = "/Users/normrasmussen/Documents/Northpass/Scripts/G2_Unenroll/g2mca.csv"
basecsv = "/Users/normrasmussen/Documents/Northpass/Scripts/G2_Unenroll/g2mca_112122.csv"
apiKey = "JRDpCGQ7vSRiva6t5OkWDr5eJ" #G2
def mainFunc(basecsv):
def mainFunc(basecsv, apiKey):
readData = pd.read_csv(
basecsv,
index_col=False,
)
try:
readData.loc[
readData['Course Name'].isin(['G2 Profile Anatomy'])]
readData.loc[
readData['Course Name'].isin('Profile Performance & Lead Management')]
readData.loc[
readData['Course Name'].isin('Review Tracking & Brand Building')]
readData.loc[
readData['Course Name'].isin('The Review Rundown')]
extractedList = readData.loc[
readData['Attempt Start'].isnull(),
'Learner Name'].tolist()
print(extractedList)
# newList = [*set(extractedList)]
#findUuids(newList, readData)
except:
print("Not Working")
readData.loc[readData['Course Name'].isin([
'G2 Profile Anatomy', 'Profile Performance & Lead Management',
'Review Tracking & Brand Building', 'The Review Rundown'])]
extractedList = readData.loc[readData['Attempt Start'].isnull(),'Email'].tolist()
fourOccs = Counter(extractedList)
finalNames = []
for name, occurences in fourOccs.items():
if occurences == 4:
finalNames.append(name)
findUuids(finalNames, readData, apiKey)
#def findUuids(newList, readData):
# try:
# for name in newList:
# uuidList = readData.loc[
# readData['Learner Name'] == name),
# 'uuid'.tolist()]
# print(uuidList)
# except:
# print("An error occured")
def findUuids(finalNames, readData, apiKey):
emailUuid = []
uuidList = []
deactivateUuid = {}
try:
for name in finalNames:
baseUrlname = "https://api.northpass.com/v2/people?filter[email][eq]="
name = name
url = baseUrlname + f"{name}"
headers = {
"accept": "*/*",
"x-api-key": apiKey,
"content-type": "application/json",
}
response = requests.get(url, headers=headers)
response = response.json()
uuid = response["data"][0]["id"]
uuidList.append(uuid)
deactivateUuid.update({name: uuid})
emailUuid.append(deactivateUuid)
except:
print("An error occured")
finally:
print(deactivateUuid)
removeFromGroup(uuidList, apiKey)
def removeFromGroup(uuidList, apiKey):
numRemoved = 0
badUuid = []
for uuid in uuidList:
uuidList = []
url = f"https://api.northpass.com/v2/people/{uuid}/relationships/groups"
headers = {
"accept": "application/json",
"content-type": "application/json",
"X-Api-Key": apiKey
}
payload = {"data": [
{
"id": "d78af2ad-a6c8-4016-90a4-fb00bcc67891",
"type": "membership-groups"
}
]}
response = requests.delete(url, json=payload, headers=headers)
status = response.status_code
if response.status_code == 200:
print(f"UserID {uuid} okay to be deleted.")
numRemoved += 1
uuidList.append(uuid)
else:
print(f"Some other error {status} for {uuid}")
badUuid.append(uuid)
print(f"Complete! {numRemoved} people removed from group.")
print("Bad UUIDS: ")
print(badUuid)
if __name__ == "__main__":
mainFunc(basecsv)
mainFunc(basecsv, apiKey)

File diff suppressed because it is too large Load Diff