HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
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