File: //home/arjun/projects/unlimited-leads/Unlimited-Leads-Be/services/numverify.py
from django.conf import settings
import requests
import time
class NUMVERIFY:
def __init__(self):
self.NUMVERIFY_ACCESS_KEY = settings.NUMVERIFY_ACCESS_KEY
def verify_numbers(self, phone_data: list) -> list:
"""
Verifies a list of phone numbers in bulk.
Args:
phone_data (list): A list of dictionaries, each containing:
- 'phone_number' (str): The phone number to verify.
- 'country_code' (str): The country code for the phone number.
Returns:
list: A list of results, where each result is the API response for a phone number.
"""
url = "https://apilayer.net/api/validate"
results = []
for item in phone_data:
params = {
'access_key': self.NUMVERIFY_ACCESS_KEY,
'number': item['phone_number'],
'country_code': item['country_code'],
'format': 1
}
response = requests.get(url, params=params)
results.append(response.json())
time.sleep(1)
return results