A ton of updates for Cin7's templates for multi-product people. Finished the first half of the mass-delete script for Sandata.

This commit is contained in:
Norm Rasmussen
2024-05-08 17:37:17 -04:00
parent 86ef310892
commit 4785ff6283
26 changed files with 359 additions and 217 deletions

View File

@ -1,35 +1,64 @@
import Apikeys
import requests
import pandas as pd
import pprint
pp = pprint.PrettyPrinter(indent=4)
df = pd.DataFrame()
BASEURL = "https://api.northpass.com/v2"
LEARNFILTER = "?filter[partnerships_type][eq]=Partnerships::Learner"
APIKEY = Apikeys.SANDATA
HEADERS = { "accept": "application/json", "X-Api-Key": APIKEY }
HEADERS = {"accept": "application/json", "X-Api-Key": APIKEY}
PERSON_GROUPS = []
PPL_DELETIONS = []
def get_people():
count = 0
while True:
count =+ 1
url = f"{BASEURL}/people/{LEARNFILTER}&limit=100&page={count}"
url = f"{BASEURL}/people{LEARNFILTER}&limit=100&page={count}"
resp = requests.get(url, headers=HEADERS)
json = resp.json()
nextlink = json['links']
nextlink = json["links"]
print(count)
count += 1
for data in json["data"]:
id = data["id"]
PERSON_GROUPS.append(id)
email = data["attributes"]["email"]
groups = data["relationships"]["groups"]
for key, val in groups.items():
if groups != "":
for group in val:
uuid = group["id"]
group_url = f"https://api.northpass.com/v2/groups/{uuid}"
response = requests.get(group_url, headers=HEADERS)
group_resp = response.json()
group_name = group_resp["data"]["attributes"]["name"]
# print(email, group_name)
if "- OH" not in group_name or "- CA" not in group_name:
PPL_DELETIONS.append(id)
print(email, group_name)
PERSON_GROUPS.append((id, email, group_name))
for data in json['data']:
id = data['id']
groups = data['relationships']['groups']
print(groups)
for key,val in groups.items():
if groups == "":
print(groups)
else:
print("Else")
PERSON_GROUPS.append((id, email, "No Group"))
if "next" not in nextlink:
break
dataframe = df.from_records(PERSON_GROUPS)
print(dataframe)
print(len(PERSON_GROUPS))
# def parse_groups(id, grouplist):
# for uuid in grouplist:
# url = "https://api.northpass.com/v2/groups/{uuid}"
"""
Bulk delete endpoint: https://api.northpass.com/v2/bulk/people/delete
Payload:

View File

@ -1,45 +1,82 @@
import tmp
WEBHOOK_PAYLOAD = {
id: " dc9aafe3-eee7-4d50-a480-3bd9831b893a",
email: " it",
type: " person_properties",
attributes: {
properties: {
agency_name: " 32",
agency_id: " 323",
medicaid_id: " 22222",
provider_id: " 2123231234",
learner_role: " Agency Billing",
learner_state: " Ohio",
evv - selection: " aw;jakkd'l",
oh_group_name: " EVV",
ca_group_name: " None",
cal_evv_id: " None",
successfully_completed_secondary_registration: true,
}
},
# WEBHOOK_PAYLOAD = {
# "id": "dc9aafe3-eee7-4d50-a480-3bd9831b893a",
# "email": "it",
# "type": "person_properties",
# "attributes": {
# "properties": {
# "agency_name": "32",
# "agency_id": "323",
# "medicaid_id": "22222",
# "provider_id": "2123231234",
# "learner_role": "Agency Billing",
# "learner_state": "Ohio",
# "evv_radio_selection": "Alt EVV Aggregator",
# "cal_evv_id": "None",
# "successfully_completed_secondary_registration": True,
# }
# },
# }
webhook_payload = {
"payload": {
"array": [
{
"id": "e134030d-a2a9-4de2-b4d5-87081feee18a",
"email": "gwalden@sandata.com",
"type": "person_properties",
"attributes": {
"properties": {
"agency_name": "Test 2",
"agency_id": "Test 2",
"medicaid_id": "54321",
"provider_id": "0987654321",
"learner_role": "Agency Billing",
"learner_state": "TN",
"evv_radio_selection": "Agency EVV",
"successfully_completed_secondary_registration": True,
"cal_evv_id": None
}
}
}
]
},
"params": {}
}
def main(input):
payload = input["webhook_payload"]
for item in input["webhook_payload"]:
evv = item["attributes"]["properties"]["oh_group_name"]
state = item["attributes"]["properties"]["learner_state"]
group_result = [ref_state for ref_state in REF if state in ref_state]
try:
if len(group_result) > 1:
for group in group_result:
if evv in group:
group_uuid = group[2]
else:
group_uuid = group_result[0][2]
except ValueError:
pass
finally:
return {"group_uuid": group_uuid}
# def main(input):
# payload = input["webhook_payload"]
# for item in input["webhook_payload"]:
# evv = item["attributes"]["properties"]["evv_radio_selection"]
# state = item["attributes"]["properties"]["learner_state"]
# group_result = [ref_state for ref_state in REF if state in ref_state]
# try:
# if len(group_result) > 1:
# for group in group_result:
# if evv in group:
# group_uuid = group[2]
# else:
# group_uuid = group_result[0][2]
# except ValueError:
# pass
# finally:
# return {"group_uuid": group_uuid}
for item in webhook_payload['payload']['array']:
evv = item['attributes']['properties']['evv_radio_selection']
state = item['attributes']['properties']['learner_state']
id_pair = f"{state} {evv}"
group_result = [ref_state for ref_state in tmp.REF if state in ref_state]
if len(group_result) > 1:
for group in group_result:
if id_pair in group[1]:
group_uuid = group[2]
print(group_uuid)
else:
group_uuid = group_result[0][2]
print(group_uuid)
if __name__ == "__main__":
main()
# if __name__ == "__main__":
# # main()
# main2()