-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhone_Number_Info.py
More file actions
68 lines (54 loc) · 2.12 KB
/
Phone_Number_Info.py
File metadata and controls
68 lines (54 loc) · 2.12 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
# Import the phonenumbers library
import phonenumbers
# Import necessary tools from phonenumbers
from phonenumbers import geocoder, carrier, timezone
def get_phone_number_info(enter_num, region='US'):
"""
Get information about a phone number.
Args:
enter_num (str): The phone number entered by the user.
region (str): The default region for parsing the phone number.
Returns:
dict: A dictionary containing phone number information.
"""
try:
# Parse the entered phone number to create a phone number object
phone_num = phonenumbers.parse(enter_num, region)
# Check if the phone number is valid
valid = phonenumbers.is_valid_number(phone_num)
# Get geographical location
location = geocoder.description_for_number(phone_num, 'en')
# Get carrier (service provider)
phone_carrier = carrier.name_for_number(phone_num, 'en')
# Get time zone(s)
time_zones = timezone.time_zones_for_number(phone_num)
return {
'phone_number': phone_num,
'valid': valid,
'location': location,
'carrier': phone_carrier,
'time_zones': time_zones
}
except phonenumbers.NumberParseException as e:
return {
'error': f"Error parsing phone number: {e}"
}
def main():
"""
Main function to prompt the user and display phone number information.
"""
# Prompt the user to enter a phone number
enter_num = input("Enter a phone number (with country code, e.g., +1234567890): ").strip()
# Get phone number information
info = get_phone_number_info(enter_num)
# Display the information
if 'error' in info:
print(info['error'])
else:
print(f"Phone Number: {info['phone_number']}")
print(f"Valid: {'Yes' if info['valid'] else 'No'}")
print(f"Geographical Location: {info['location']}")
print(f"Carrier: {info['carrier']}")
print(f"Time Zone(s): {', '.join(info['time_zones'])}")
if __name__ == "__main__":
main()