-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapollo_api.py
More file actions
159 lines (138 loc) · 4.09 KB
/
apollo_api.py
File metadata and controls
159 lines (138 loc) · 4.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import json
import time
import timeit
from random import random
from multiprocessing import Pool
from time import sleep
import pandas as pd
import requests
from source.utils import *
original = open("data/people/BAcsv.csv", 'r+')
websites = open("data/people/apollo-accounts-export (5).csv", 'r+')
required_pages = 30
reader = csv.reader(original)
reader2 = csv.reader(websites)
csv_header = ["organization", "first_name", "last_name", 'headline', 'city', 'state', 'country', 'linkedin_url']
states = open("data/Static/states.csv", 'r+').read().split('\n')
reader3 = csv.reader(states)
state = []
for row in states:
state.append(row.split(','))
abbr = Convert(state)
combined = []
one = []
two = []
three = []
four = []
domain_text = ""
for row in reader:
one.append(row)
for sub in reader2:
two.append(sub)
for i in one:
for j in two:
if j[0].lower() == str(i[1]).lower():
dummy_location = i[2].split(',')
location = dummy_location[0].lower()
try:
state = abbr[dummy_location[1].strip()]
except:
state = ""
i.pop(2)
i.append(location)
i.append(state)
raw_domain = get_hostname(j[1])
k = i + [raw_domain]
combined.append(k)
domain_text = domain_text + raw_domain.strip() + "\n"
# print(combined)
domain = domain_text
result_list = []
new_data = [{'data1': 'val1'}, {'data2': 'val2'}]
titles = ["hr", "Recruiter", 'talent', 'people', 'recruiting', 'recruit']
url = "https://api.apollo.io/v1/mixed_people/search"
headers = {
'Content-Type': 'application/json',
'Cache-Control': 'no-cache',
'x-api-key': 'xQx9DESeSh_ZQb39lIUVwQ',
}
def extract_companies(people):
companies = []
for k, v in enumerate(people):
if v:
pass
companies.append(v[0].lower())
return companies
def listify_companies(companies):
index = {req_word: [idx for idx, word in enumerate(companies) if word == req_word] for req_word in
set(companies)}
return index
def Search(page):
start = timeit.default_timer()
payload = json.dumps({
"api_key": "xQx9DESeSh_ZQb39lIUVwQ",
"q_organization_domains": domain,
"person_titles": titles,
"page": page,
"per_page": "200",
})
response = requests.request("POST", url, headers=headers, data=payload)
data = response.json()
people = data['people']
for row in data['contacts']:
people.append(row)
for v in people:
try:
if v['country'] != 'United States':
pass
else:
v['organization'] = v['organization']['name']
result_list.append(v)
except:
pass
return result_list
for page in range(1, 100):
val = Search(page)
if len(val) < 3:
break
for row in val:
four.append(row)
# print(len(four), four)
df = pd.DataFrame(four)
# print(df)
df = df[csv_header]
df.drop_duplicates(subset='linkedin_url', keep="first", inplace=True)
df.to_csv('data/people/test2.csv', encoding='utf-8', index=False)
products_list = df.values.tolist()
# print(products_list)
comp = extract_companies(products_list)
list2 = listify_companies(comp)
# time.sleep(500)
for k, v in enumerate(combined):
temp = []
# print(v)
try:
loc = list2[v[1].lower()]
# print(loc)
for zz in loc:
if products_list[zz][4] == v[2] and products_list[zz][5] == v[3]:
# print("people", products_list[zz])
temp.insert(0, v + products_list[zz])
elif products_list[zz][5] == v[3]:
# print("people", products_list[zz])
temp.insert(4, v + products_list[zz])
else:
# print("people", products_list[zz])
temp.insert(10, v + products_list[zz])
except:
pass
temp = temp[:5]
for row in temp:
three.append(row)
# print("One", three)
try:
with open('test-file.csv', 'w') as zzzz:
writer = csv.writer(zzzz)
writer.writerows(three)
except:
pass