Emergency script for Anthology that was abanonded. CSV updates. HackerRank notes
This commit is contained in:
52
Scripts/API_Tests/antho-map-domains-from-csv.py
Normal file
52
Scripts/API_Tests/antho-map-domains-from-csv.py
Normal 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)
|
||||
18
Scripts/API_Tests/antho-pandas.py
Normal file
18
Scripts/API_Tests/antho-pandas.py
Normal 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}
|
||||
Reference in New Issue
Block a user