analizar_telefono()
Interactive function that analyzes international phone numbers and extracts comprehensive information including carrier, location, validity, and formatting.Function Signature
Parameters
This function takes no parameters. It prompts the user interactively for input.Input Methods
The function supports two input methods:Complete number with country codeUser enters the full international number with + prefix (e.g., “+593 99 123 4567”)
Separate partsUser enters country code and number separately:
- Country code without + (e.g., “593”)
- Phone number (e.g., “991234567”)
Input Format Examples
Return Value
This function does not return a value. It prints results to the console and saves them to a file.
Output Data
The function extracts and displays the following information:Validation Status
Whether the number is valid according to phone number rules. Displayed with green checkmark (✓) or red cross (✗).
Whether the number is possible (has correct length). Displayed with green checkmark (✓) or yellow warning (!).
Number Formats
International format (e.g., “+1 650-253-0000”)
E.164 format - standardized international format (e.g., “+16502530000”)
National format as dialed within the country (e.g., “(650) 253-0000”)
Geographic Information
Country or region name in Spanish (from geocoder)
Region name in English (from geocoder)
Numeric country calling code (e.g., 1 for US, 44 for UK)
The national number portion without country code
Carrier Information
Mobile carrier/operator name in Spanish. Returns “Desconocido” if not found.
Number Type
Numeric type code from phonenumbers library:
- 0: Fijo (Fixed line)
- 1: Móvil (Mobile)
- 2: Fijo o Móvil (Fixed line or mobile)
- 3: Gratuito (Toll-free)
- 4: Tarifa Premium (Premium rate)
- 5: Costo Compartido (Shared cost)
- 6: VoIP
- 7: Número Personal (Personal number)
- 8: Pager
- 9: UAN (Universal Access Number)
- 10: Desconocido (Unknown)
Timezone
List of timezone identifiers for the phone number’s location (e.g., [“America/New_York”, “America/Detroit”])
Code Example
Side Effects
- Creates
Resultados_Tracker/directory if it doesn’t exist - Saves detailed results to:
Telefono_{country_code}{national_number}_{timestamp}.txt - Prints formatted output to console with colored text
- Displays interactive prompts for user input
- Calls
pausar()at the end to wait for user acknowledgment
Validation Logic
The function performs comprehensive validation:- Format validation: Ensures the input can be parsed as a phone number
- Validity check: Uses phonenumbers library’s
is_valid_number()to check against numbering plans - Possibility check: Uses
is_possible_number()to verify the number length is possible
Exception Handling
Raised when the phone number cannot be parsed. Function catches this and displays:
[!] Error al parsear número: {exception_message}Any other exception is caught and displayed as:
[!] Error: {exception_message}Usage in Code
validar_telefono()
Validates whether a phone number is valid according to international numbering plans. This is a non-interactive utility function.Function Signature
Parameters
Complete international phone number with country code. Should include + prefix (e.g., “+1 650 253 0000”).
Return Value
Returns
True if the number is valid according to the phonenumbers library validation rules, False otherwise.Validation Process
- Parses the input string into a PhoneNumber object using
phonenumbers.parse() - Validates against international numbering plans using
phonenumbers.is_valid_number() - Returns
Falseif any exception occurs during parsing or validation
Code Example
Exception Handling
Any exception during parsing or validation is caught silently and the function returns
False. This includes:NumberParseException- Invalid format or unparseable inputAttributeError- None or invalid type passed- Any other exception from the phonenumbers library
Best Practices
- Always include the + prefix in the phone number string
- Validate before analysis - Use this function before calling
analizar_telefono()programmatically - Handle False gracefully - Provide user feedback when validation fails
- Use for bulk validation - This function is suitable for validating lists of numbers
Integration Example
Dependencies
Both phone methods require thephonenumbers library:
phonenumbers.parse()- Parse string to PhoneNumber objectphonenumbers.is_valid_number()- Validate against numbering plansphonenumbers.is_possible_number()- Check if length is possiblephonenumbers.format_number()- Format in various standardsgeocoder- Geographic location informationcarrier- Mobile carrier/operator informationtimezone- Timezone information for the number