-
Notifications
You must be signed in to change notification settings - Fork 0
/
app_test2.py
49 lines (39 loc) · 1.44 KB
/
app_test2.py
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
import csv
import urllib.request, json
import time
from person import Person
from urllib.error import HTTPError
req = urllib.request.Request('https://api.fullcontact.com/v3/person.enrich')
req.add_header('Authorization', 'Bearer CvIRCOBjXDYH9jPB7jTE0bQGn3OydhlM')
personArray = []
with open('/home/roger/Downloads/contatos3.csv') as csvfile:
fileReader = csv.reader(csvfile, delimiter=' ', quotechar='|')
for email in fileReader:
data = json.dumps({
"email": email[0],
}).encode('utf')
try:
response = urllib.request.urlopen(req,data)
string = response.read().decode('utf-8')
personData = email[0] + ": " + string
personArray.append(personData)
print('Person saved')
time.sleep(10)
except HTTPError as e:
if (e.code == 404):
print('Not data found for email: ', email[0])
time.sleep(10)
else:
if (e.code == 400):
print('Blacklist case: ', email[0])
time.sleep(10)
else:
print('Erro')
print(e.read())
break
with open('people_data.csv', 'w') as csvfile:
fieldnames = ['data']
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
for person in personArray:
writer.writerow({'data': person})