File size: 1,907 Bytes
dc960e3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import requests
import json
from datetime import date, datetime, timedelta
import os

from typing import Optional, Dict, Union, List


def validate(number: str, country: str='UY', toolbench_rapidapi_key: str='088440d910mshef857391f2fc461p17ae9ejsnaebc918926ff'):
    """
    "Free and easy. Validate any phone number, from any country.
		Get type of number (for example, fixed line or mobile), the location of the number, and also reformat the number into local and international dialing formats."
    number: 1_ Option: local format (without prefix):
Example: 94887799

2_ Option: format E 164:
Recommended: starting with symbol + followed by country prefix and number, without blank spaces
Remark: the + symbol in a url is escaped for the text %2B leaving %2B59894887799
Example: +59894887799 

1_ Opción: formato local (sin prefijo):
Ejemplo: 94887799

2_ Opción: formato E 164:
Recomendado: comenzando con símbolo + seguido de prefijo país y número, sin espacios en blanco
Observación: el símbolo + en una url se escapea para el texto %2B quedando %2B59894887799
Ejemplo: +59894887799
        country: Format: ISO 3166-1 alpha-2 code
Remark: in capital letters.
Optional if the number parameter starts with the + symbol 

Formato: ISO 3166-1 alpha-2 code
Observación: en mayúsculas.
Opcional si el parametro number comienza con el símbolo +
        
    """
    url = f"https://phonenumbervalidatefree.p.rapidapi.com/ts_phonenumbervalidatetest.jsp"
    querystring = {'number': number, }
    if country:
        querystring['country'] = country
    
    headers = {
            "X-RapidAPI-Key": toolbench_rapidapi_key,
            "X-RapidAPI-Host": "phonenumbervalidatefree.p.rapidapi.com"
        }


    response = requests.get(url, headers=headers, params=querystring)
    try:
        observation = response.json()
    except:
        observation = response.text
    return observation