Finished/refactored the add-to-csv script for Talkspace to move faster and not make so many API calls. Added some notes for Datasnipper.

This commit is contained in:
Norm Rasmussen
2023-12-12 17:22:13 -05:00
parent b35a650a11
commit b8dd4f0fe6
7 changed files with 25116 additions and 1 deletions

View File

@ -261,3 +261,19 @@ Ask Allyson about Zoom integration updates.... they aren't sure if they want to
Justin is on Candide's team but unable to make it.
Manager permissions continue to be an issue.
## 12/12/2023
### Mapping for Workato
| -- | -- |
| Packages in HubSpot | Learning Path |
| Enterprise | Introduction to DataSnipper - Enterprise |
| Professional | Introduction to DataSnipper - Professional |
| Basic | Introduction to DataSnipper - Basics |
| Advanced | Introduction to DataSnipper - Professional |
| N/A | Introduction to DataSnipper - Professional |
- Basics LP: f708a9c9-9fb4-460f-9f79-5be9579854b4
- Professional LP: af8e387e-203f-42a2-9117-2e9ff14d5115
- Enterprise LP: f19bc248-c430-4781-beef-b3ba4f377bac

View File

@ -24,11 +24,12 @@ def load_file(basefile):
if os.path.isfile(basefile):
print(f"File found! Importing {basefile}")
for email in completions.itertuples():
row_num = email[1]
row_num = email[0]
row_dict = {"row_num": row_num}
email = email[3]
url = uuid_url + f"{email}"
response = requests.get(url, headers=headers)
print(response)
if response.status_code == 200:
response = response.json()
uuid = response["data"][0]["id"]
@ -38,6 +39,7 @@ def load_file(basefile):
userid = data["data"]["attributes"]["properties"]["user_id"]
row_dict["userid"] = userid
dict_list.append(row_dict)
print(dict_list)
print("No errors! Passing along the dictionary!")
except KeyError as e:
print(f"{e} and the rest")

View File

@ -0,0 +1,97 @@
import requests
import pandas as pd
from pathlib import Path
import Apikeys
import os
import ts_lstdict
basefile = "/Users/normrasmussen/Downloads/ts-mca.csv"
api_key = Apikeys.TALKSPACE_1099
uuid_url = "https://api.northpass.com/v2/people?filter[email][eq]="
prop_url = "https://api.northpass.com/v2/properties/people/"
headers = {
"accept": "*/*",
"x-api-key": api_key,
"content-type": "application/json",
}
LISTDICT = ts_lstdict.LISTDICT
def load_file(basefile):
dict_list = []
row_dict = {}
basefile = Path(basefile)
completions = pd.read_csv(basefile)
curr_index = 0
parsed_list = []
try:
if os.path.isfile(basefile):
print(f"File found! Importing {basefile}")
for email in completions.itertuples():
row_num = email[0]
name = email[1]
email = email[3]
row_dict = {
"row_num": row_num,
"name": name,
"userid": "",
"email": email,
}
dict_list.append(row_dict)
print(len(dict_list))
tempdf = pd.DataFrame(dict_list)
tempdf.drop_duplicates(subset=["name"], keep="first", inplace=True)
dict_list = tempdf.to_dict("records")
print(len(dict_list))
except KeyError as e:
print(f"{e} Error")
finally:
make_calls(dict_list)
def make_calls(dict_list):
final_list = []
for row_dict in dict_list:
name = row_dict["name"]
url = uuid_url + f"{row_dict['email']}"
response = requests.get(url, headers=headers)
print(f"running api call for {name}")
if response.status_code == 200:
response = response.json()
try:
uuid = response["data"][0]["id"]
url2 = prop_url + f"{uuid}"
response = requests.get(url2, headers=headers)
data = response.json()
userid = data["data"]["attributes"]["properties"]["user_id"]
row_dict["userid"] = userid
except IndexError as e:
print(f"{e} Second error!")
finally:
pass
if row_dict["userid"] is None:
pass
else:
final_list.append(row_dict)
print(len(final_list))
def add_to_csv(LISTDICT):
completions = pd.read_csv(basefile)
for info in LISTDICT:
print(info)
row = info["name"]
pid = info["userid"]
# print(f"PID IS {pid}")
completions.loc[completions.index[row], "userid"] = pid
#completions = completions[completions["userid"] != "0"]
# completions = completions.iloc[:, 0:]
print(completions)
completions.to_csv(
"/Users/normrasmussen/Downloads/Talkspace1099-Completions-All-IDS.csv",
index=False,
)
if __name__ == "__main__":
# load_file(basefile)
add_to_csv(LISTDICT)

File diff suppressed because it is too large Load Diff

8
Scripts/dict_test.py Normal file
View File

@ -0,0 +1,8 @@
test_list = [
{"row_num":0, "name":"hello"},
{"row_num":1, "name":"goodbye"}
]
if "goodbye" in test_list[0].values():
print("It Exists!")
else:
print("it doesn't exist")

12496
Scripts/ts_lstdict.py Normal file

File diff suppressed because it is too large Load Diff