Backing up for the day. Just TS script stuff.
This commit is contained in:
@ -1,32 +1,31 @@
|
|||||||
import requests
|
import requests
|
||||||
|
import numpy as np
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import Apikeys
|
import Apikeys
|
||||||
import os
|
import os
|
||||||
import ts_lstdict
|
import ts_lstdict
|
||||||
|
|
||||||
basefile = "/Users/normrasmussen/Downloads/ts-mca.csv"
|
BASEFILE = "/Users/normrasmussen/Downloads/ts-completions.csv"
|
||||||
api_key = Apikeys.TALKSPACE_1099
|
API_KEY = Apikeys.TALKSPACE_1099
|
||||||
uuid_url = "https://api.northpass.com/v2/people?filter[email][eq]="
|
UUID_URL = "https://api.northpass.com/v2/people?filter[email][eq]="
|
||||||
prop_url = "https://api.northpass.com/v2/properties/people/"
|
PROP_URL = "https://api.northpass.com/v2/properties/people/"
|
||||||
headers = {
|
HEADERS = {
|
||||||
"accept": "*/*",
|
"accept": "*/*",
|
||||||
"x-api-key": api_key,
|
"x-api-key": API_KEY,
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
}
|
}
|
||||||
LISTDICT = ts_lstdict.LISTDICT
|
LISTDICT = ts_lstdict.LISTDICT
|
||||||
|
|
||||||
|
|
||||||
def load_file(basefile):
|
def load_file():
|
||||||
dict_list = []
|
dict_list = []
|
||||||
row_dict = {}
|
row_dict = {}
|
||||||
basefile = Path(basefile)
|
file = Path(BASEFILE)
|
||||||
completions = pd.read_csv(basefile)
|
completions = pd.read_csv(file)
|
||||||
curr_index = 0
|
|
||||||
parsed_list = []
|
|
||||||
try:
|
try:
|
||||||
if os.path.isfile(basefile):
|
if os.path.isfile(file):
|
||||||
print(f"File found! Importing {basefile}")
|
print(f"File found! Importing {file}")
|
||||||
for email in completions.itertuples():
|
for email in completions.itertuples():
|
||||||
row_num = email[0]
|
row_num = email[0]
|
||||||
name = email[1]
|
name = email[1]
|
||||||
@ -53,18 +52,23 @@ def make_calls(dict_list):
|
|||||||
final_list = []
|
final_list = []
|
||||||
for row_dict in dict_list:
|
for row_dict in dict_list:
|
||||||
name = row_dict["name"]
|
name = row_dict["name"]
|
||||||
url = uuid_url + f"{row_dict['email']}"
|
url = UUID_URL + f"{row_dict['email']}"
|
||||||
response = requests.get(url, headers=headers)
|
response = requests.get(url, headers=HEADERS)
|
||||||
print(f"running api call for {name}")
|
print(f"running api call for {name}")
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
response = response.json()
|
response = response.json()
|
||||||
try:
|
try:
|
||||||
uuid = response["data"][0]["id"]
|
uuid = response["data"][0]["id"]
|
||||||
url2 = prop_url + f"{uuid}"
|
url2 = PROP_URL + f"{uuid}"
|
||||||
response = requests.get(url2, headers=headers)
|
response = requests.get(url2, headers=HEADERS)
|
||||||
data = response.json()
|
try:
|
||||||
userid = data["data"]["attributes"]["properties"]["user_id"]
|
data = response.json()
|
||||||
row_dict["userid"] = userid
|
userid = data["data"]["attributes"]["properties"]["user_id"]
|
||||||
|
row_dict["userid"] = userid
|
||||||
|
except JSONDecodeError as e:
|
||||||
|
print(e)
|
||||||
|
finally:
|
||||||
|
pass
|
||||||
except IndexError as e:
|
except IndexError as e:
|
||||||
print(f"{e} Second error!")
|
print(f"{e} Second error!")
|
||||||
finally:
|
finally:
|
||||||
@ -74,24 +78,24 @@ def make_calls(dict_list):
|
|||||||
else:
|
else:
|
||||||
final_list.append(row_dict)
|
final_list.append(row_dict)
|
||||||
print(len(final_list))
|
print(len(final_list))
|
||||||
|
add_to_csv(final_list)
|
||||||
|
|
||||||
def add_to_csv(LISTDICT):
|
|
||||||
completions = pd.read_csv(basefile)
|
def add_to_csv(final_list):
|
||||||
for info in LISTDICT:
|
# completions = pd.read_csv(BASEFILE)
|
||||||
print(info)
|
completions['user_id'] = ""
|
||||||
|
for info in final_list:
|
||||||
row = info["name"]
|
row = info["name"]
|
||||||
|
email = info["email"]
|
||||||
pid = info["userid"]
|
pid = info["userid"]
|
||||||
# print(f"PID IS {pid}")
|
completions.loc[completions['email'] == email, 'user_id'] = pid
|
||||||
completions.loc[completions.index[row], "userid"] = pid
|
# completions['User ID'] = np.where(completions['email'] == email, pid, None)
|
||||||
#completions = completions[completions["userid"] != "0"]
|
|
||||||
# completions = completions.iloc[:, 0:]
|
|
||||||
print(completions)
|
print(completions)
|
||||||
completions.to_csv(
|
completions.to_csv(
|
||||||
"/Users/normrasmussen/Downloads/Talkspace1099-Completions-All-IDS.csv",
|
"/Users/normrasmussen/Downloads/Talkspace1099-Completions-All-IDS.csv",
|
||||||
index=False,
|
)
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# load_file(basefile)
|
load_file()
|
||||||
add_to_csv(LISTDICT)
|
# add_to_csv()
|
||||||
|
|||||||
Reference in New Issue
Block a user