Emergency script for Anthology that was abanonded. CSV updates. HackerRank notes

This commit is contained in:
Norm Rasmussen
2024-02-01 16:09:29 -05:00
parent 111d6412d6
commit 7080a3a4f3
4 changed files with 97 additions and 0 deletions

View File

@ -0,0 +1,52 @@
import pandas as pd
import requests
import Apikeys
MASTER = "~/Downloads/Anthology-Master-CSV-FirstChanges.csv"
BASEURL = "https://api.northpass.com/v2/people"
APIKEY = Apikeys.ANTHOLOGY
HEADERS = {
"accept": "*/*",
"X-Api-Key": APIKEY,
"content-type": "application/json",
}
df = pd.read_csv(MASTER)
df.dropna(how="all", axis=0, inplace=True)
COUNT = 0
for row in df.itertuples():
domain = row[1]
groups = row[2:]
# groups = list(groups)
tmplist = []
for group in groups:
group = str(group)
if "nan" not in group:
# Grab Group UUIDs
url = f"https://api.northpass.com/v2/groups?filter[name][eq]={group}"
response = requests.get(url, headers=HEADERS)
response = response.json()
data = response["data"]
for name in data:
id = name["id"]
tmplist.append(id)
rowdict = {domain: tmplist}
# Grab all people
personlist = []
COUNT += 1
url = BASEURL + f"?filter[email][cont]={domain}"
response = requests.get(url, headers=HEADERS)
response = response.json()
nextlink = response["links"]
for data in response["data"]:
person = data["id"]
personlist.append(person)
# if "next" not in nextlink:
# break
# Construct Payload for Bulk API
payload = {"payload": {"person_ids": personlist, "group_ids": tmplist}}
print(payload)

View File

@ -0,0 +1,18 @@
import pandas as pd
import os
file = "~/Downloads/Anthology-EngageT1T2-MCA-CSV.csv"
df = pd.read_csv(file)
df["engage"] = df["Groups"].str.contains("(T2)")
# print(df["engage"].value_counts())
print(df["Domain"].value_counts())
df.sort_values("Email", inplace=True)
df.drop_duplicates(subset="Email", keep=False, inplace=True)
print(df["Domain"].value_counts())
# df2 = df[[ "Domain", "Groups" ]].copy()
# print(df2)
# accounts = df["Domain"].unique().tolist()
# for x in accounts:
# df_dict = {name: df.loc[df["Domain"] == name] for name in accounts}