Chubb script for adding learners and add props. Added a state for Sandata.
This commit is contained in:
@ -16,6 +16,7 @@
|
||||
<option class="second-login-state-option" value="ID">Idaho</option>
|
||||
<option class="second-login-state-option" value="IL">Illinois</option>
|
||||
<option class="second-login-state-option" value="IN">Indiana</option>
|
||||
<option class="second-login-state-option" value="MA">Massachusetts</option>
|
||||
<option class="second-login-state-option" value="MO">Missouri</option>
|
||||
<option class="second-login-state-option" value="NV">Nevada</option>
|
||||
<option class="second-login-state-option" value="NC">North Carolina</option>
|
||||
|
||||
@ -4,6 +4,7 @@ import pprint
|
||||
import csv
|
||||
import pandas as pd
|
||||
import Apikeys
|
||||
import time
|
||||
|
||||
pp = pprint.PrettyPrinter(indent=4)
|
||||
APIKEY = Apikeys.CHUBB
|
||||
@ -12,7 +13,7 @@ HEADERS = {
|
||||
"X-Api-Key": APIKEY,
|
||||
}
|
||||
BASEURL = "https://api.northpass.com/v2/"
|
||||
IMPORTFILE = "/Users/normrasmussen/Downloads/chubb.csv"
|
||||
IMPORTFILE = "/Users/normrasmussen/Downloads/chubb-cisa-624.csv"
|
||||
|
||||
|
||||
def bulk_invite_and_group():
|
||||
@ -29,39 +30,82 @@ def bulk_invite_and_group():
|
||||
data = pd.read_csv(IMPORTFILE)
|
||||
groups = data["Group"].unique()
|
||||
groups = list(groups)
|
||||
for group in groups:
|
||||
payload = ""
|
||||
tmp_group = data[data.Group == group]
|
||||
people = list(tmp_group["Email"])
|
||||
group = str(tmp_group["Group"].unique())[2:-2]
|
||||
# print(f"Group --> {group} & Email Length --> {len(people)}")
|
||||
url = f"{BASEURL}bulk/people"
|
||||
if len(people) > 1500:
|
||||
for chunk in range(0, len(people), 1500):
|
||||
i = chunk
|
||||
try:
|
||||
for group in groups:
|
||||
payload = ""
|
||||
tmp_group = data[data.Group == group]
|
||||
people = list(tmp_group["Email"])
|
||||
group = str(tmp_group["Group"].unique())[2:-2]
|
||||
print(f"Group --> {group} & Email Length --> {len(people)}")
|
||||
url = f"{BASEURL}bulk/people"
|
||||
if len(people) > 1500:
|
||||
for chunk in range(0, len(people), 1500):
|
||||
i = chunk
|
||||
payload_1 = []
|
||||
i_to_add = people[i : i + 1500]
|
||||
for person in i_to_add:
|
||||
miniload = {"email": person, "groups": group}
|
||||
payload_1.append(miniload)
|
||||
print(f"The long length {group} payload has {len(payload_1)}")
|
||||
payload = {"data": {"attributes": {"people": payload_1}}}
|
||||
response = requests.post(url, headers=HEADERS, json=payload)
|
||||
print(f"Completed. Status code is {response.status_code}")
|
||||
else:
|
||||
payload_1 = []
|
||||
i_to_add = people[i : i + 1500]
|
||||
for person in i_to_add:
|
||||
for person in people:
|
||||
miniload = {"email": person, "groups": group}
|
||||
payload_1.append(miniload)
|
||||
print(f"The long length {group} payload has {len(payload_1)}")
|
||||
# print(f"The {group} payload has {len(payload_1)}")
|
||||
payload = {"data": {"attributes": {"people": payload_1}}}
|
||||
response = requests.post(url, headers=HEADERS, json=payload)
|
||||
print(f"Completed. Status code is {response.status_code}")
|
||||
else:
|
||||
payload_1 = []
|
||||
for person in people:
|
||||
miniload = {"email": person, "groups": group}
|
||||
payload_1.append(miniload)
|
||||
print(f"The {group} payload has {len(payload_1)}")
|
||||
payload = {"data": {"attributes": {"people": payload_1}}}
|
||||
response = requests.post(url, headers=HEADERS, json=payload)
|
||||
print(f"Completed. Status code is {response.status_code}")
|
||||
print(response.text)
|
||||
print(response.text)
|
||||
except:
|
||||
pass
|
||||
finally:
|
||||
print("Running add props from func...")
|
||||
time.sleep(3)
|
||||
add_props_from_func(people, data)
|
||||
|
||||
# add_props()
|
||||
|
||||
def add_props():
|
||||
def add_props_from_func(people, data):
|
||||
errorlist = []
|
||||
for learner_email in people:
|
||||
agency_name = data.loc[data["Email"] == learner_email, "AgencyName"]
|
||||
agname = str(agency_name.values)[2:-2]
|
||||
print(f"Learner: {learner_email} --> Agency: {agname}")
|
||||
ppl_search = f"{BASEURL}people?filter[email][eq]={learner_email}"
|
||||
ppl_response = requests.get(ppl_search, headers=HEADERS)
|
||||
try:
|
||||
ppl_data = ppl_response.json()
|
||||
nextlink = ppl_data["links"]
|
||||
learner_uuid = ppl_data["data"][0]["id"]
|
||||
|
||||
# Now update the props
|
||||
prop_url = f"{BASEURL}properties/people/bulk"
|
||||
payload = {
|
||||
"data": [
|
||||
{
|
||||
"attributes": {"properties": {"agency_name": agname }},
|
||||
"id": learner_uuid,
|
||||
"type": "person_properties",
|
||||
}
|
||||
]
|
||||
}
|
||||
propresponse = requests.post(prop_url, json=payload, headers=HEADERS)
|
||||
print(propresponse.status_code)
|
||||
if propresponse.status_code != 200:
|
||||
error_tupe = (learner_uud, learner_email, agency_name)
|
||||
errorlist.append(error_tupe)
|
||||
else:
|
||||
print(f"Looks like {learner_email} and {agency_name} was successful.")
|
||||
except TypeError as e:
|
||||
pass
|
||||
finally:
|
||||
print(f"Error list: {errorlist}")
|
||||
|
||||
|
||||
def add_props_from_csv():
|
||||
errorlist = []
|
||||
df = pd.DataFrame()
|
||||
data = pd.read_csv(IMPORTFILE)
|
||||
@ -82,7 +126,7 @@ def add_props():
|
||||
payload = {
|
||||
"data": [
|
||||
{
|
||||
"attributes": {"properties": {"agency_name": agency_name }},
|
||||
"attributes": {"properties": {"agency_name": agency_name}},
|
||||
"id": learner_uuid,
|
||||
"type": "person_properties",
|
||||
}
|
||||
@ -102,5 +146,4 @@ def add_props():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
add_props()
|
||||
#bulk_invite_and_group()
|
||||
bulk_invite_and_group()
|
||||
|
||||
22
Scripts/API_Tests/tmp_pandas.py
Normal file
22
Scripts/API_Tests/tmp_pandas.py
Normal file
@ -0,0 +1,22 @@
|
||||
import requests
|
||||
import json
|
||||
import pprint
|
||||
import csv
|
||||
import pandas as pd
|
||||
|
||||
IMPORTFILE = "/Users/normrasmussen/Downloads/chubb-old.csv"
|
||||
|
||||
data = pd.read_csv(IMPORTFILE)
|
||||
groups = data["Group"].unique()
|
||||
print(groups)
|
||||
groups = list(groups)
|
||||
for group in groups:
|
||||
payload = ""
|
||||
tmp_group = data[data.Group == group]
|
||||
people = list(tmp_group["Email"])
|
||||
group = str(tmp_group["Group"].unique())[2:-2]
|
||||
for learner_email in people:
|
||||
agency_name = data.loc[data['Email'] == learner_email, 'AgencyName']
|
||||
agname = str(agency_name.values)[2:-2]
|
||||
print(agname)
|
||||
# ppl_search = f"{BASEURL}people?filter[email][eq]={learner_email}"
|
||||
Reference in New Issue
Block a user