Backing up for the day. Just TS script stuff.

This commit is contained in:
Norm Rasmussen
2023-12-13 16:26:32 -05:00
parent b8dd4f0fe6
commit f39ddb789d

View File

@ -1,32 +1,31 @@
import requests
import numpy as np
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 = {
BASEFILE = "/Users/normrasmussen/Downloads/ts-completions.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,
"x-api-key": API_KEY,
"content-type": "application/json",
}
LISTDICT = ts_lstdict.LISTDICT
def load_file(basefile):
def load_file():
dict_list = []
row_dict = {}
basefile = Path(basefile)
completions = pd.read_csv(basefile)
curr_index = 0
parsed_list = []
file = Path(BASEFILE)
completions = pd.read_csv(file)
try:
if os.path.isfile(basefile):
print(f"File found! Importing {basefile}")
if os.path.isfile(file):
print(f"File found! Importing {file}")
for email in completions.itertuples():
row_num = email[0]
name = email[1]
@ -53,18 +52,23 @@ 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)
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
url2 = PROP_URL + f"{uuid}"
response = requests.get(url2, headers=HEADERS)
try:
data = response.json()
userid = data["data"]["attributes"]["properties"]["user_id"]
row_dict["userid"] = userid
except JSONDecodeError as e:
print(e)
finally:
pass
except IndexError as e:
print(f"{e} Second error!")
finally:
@ -74,24 +78,24 @@ def make_calls(dict_list):
else:
final_list.append(row_dict)
print(len(final_list))
add_to_csv(final_list)
def add_to_csv(LISTDICT):
completions = pd.read_csv(basefile)
for info in LISTDICT:
print(info)
def add_to_csv(final_list):
# completions = pd.read_csv(BASEFILE)
completions['user_id'] = ""
for info in final_list:
row = info["name"]
email = info["email"]
pid = info["userid"]
# print(f"PID IS {pid}")
completions.loc[completions.index[row], "userid"] = pid
#completions = completions[completions["userid"] != "0"]
# completions = completions.iloc[:, 0:]
completions.loc[completions['email'] == email, 'user_id'] = pid
# completions['User ID'] = np.where(completions['email'] == email, pid, None)
print(completions)
completions.to_csv(
"/Users/normrasmussen/Downloads/Talkspace1099-Completions-All-IDS.csv",
index=False,
)
"/Users/normrasmussen/Downloads/Talkspace1099-Completions-All-IDS.csv",
)
if __name__ == "__main__":
# load_file(basefile)
add_to_csv(LISTDICT)
load_file()
# add_to_csv()