-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbulk_verify.py
More file actions
91 lines (71 loc) · 2.26 KB
/
bulk_verify.py
File metadata and controls
91 lines (71 loc) · 2.26 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
"""
Bulk verify emails using the OrbiSearch API.
"""
import time
import requests
API_KEY = "your_api_key_here"
BASE_URL = "https://api.orbisearch.com"
def submit_bulk_job(emails: list[str]) -> dict:
"""Submit a bulk verification job."""
response = requests.post(
f"{BASE_URL}/v1/bulk",
json=emails,
headers={
"X-API-Key": API_KEY,
"Content-Type": "application/json",
},
)
response.raise_for_status()
return response.json()
def get_job_status(job_id: str) -> dict:
"""Get the status of a bulk job."""
response = requests.get(
f"{BASE_URL}/v1/bulk/{job_id}",
headers={"X-API-Key": API_KEY},
)
response.raise_for_status()
return response.json()
def get_job_results(job_id: str) -> dict:
"""Get the results of a completed bulk job."""
response = requests.get(
f"{BASE_URL}/v1/bulk/{job_id}/results",
headers={"X-API-Key": API_KEY},
)
response.raise_for_status()
return response.json()
def verify_bulk(emails: list[str], poll_interval: int = 5) -> list[dict]:
"""
Verify a list of emails and wait for results.
Args:
emails: List of email addresses to verify
poll_interval: Seconds between status checks
Returns:
List of verification results
"""
# Submit the job
job = submit_bulk_job(emails)
job_id = job["job_id"]
print(f"Job submitted: {job_id}")
print(f"Total emails: {job['total_emails']}")
print(f"Estimated cost: {job['estimated_cost']} credits")
# Poll for completion
while True:
status = get_job_status(job_id)
print(f"Status: {status['status']} ({status['emails_processed']}/{status['total_emails']})")
if status["status"] == "complete":
break
elif status["status"] == "failed":
raise Exception("Job failed")
time.sleep(poll_interval)
# Get results
results = get_job_results(job_id)
return results["results"]
if __name__ == "__main__":
emails = [
"john@company.com",
"jane@company.com",
"info@company.com",
]
results = verify_bulk(emails)
for result in results:
print(f"{result['email']}: {result['status']} ({result.get('substatus', 'n/a')})")