-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocation.py
51 lines (39 loc) · 1.59 KB
/
location.py
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
import phonenumbers
from phonenumbers import timezone, geocoder, carrier
from geopy.geocoders import Nominatim
def get_phone_number_info(phone_number):
info = {}
# Parsing String to the Phone number
phoneNumber = phonenumbers.parse(phone_number)
# Get timezone
info['timezone'] = timezone.time_zones_for_number(phoneNumber)
# Get geolocation
geolocation = geocoder.description_for_number(phoneNumber, "en")
info['location'] = geolocation
# Get service provider
info['service_provider'] = carrier.name_for_number(phoneNumber, "en")
return info
def get_coordinates_from_address(address):
# Specify your own user-agent string here
geolocator = Nominatim(user_agent="location.py")
try:
location = geolocator.geocode(address)
if location:
return location.latitude, location.longitude
else:
return None
except Exception as e:
print(f"Error: {e}")
return None
number = input("Enter the phone number with country code: ")
# Get information about the phone number
phone_number_info = get_phone_number_info(number)
print("Phone Number Info:", phone_number_info)
# Get latitude and longitude for the current location associated with the phone number
address = f"{phone_number_info['location']}, {phone_number_info['timezone']}"
coordinates = get_coordinates_from_address(address)
if coordinates:
latitude, longitude = coordinates
print(f"Latitude: {latitude}, Longitude: {longitude}")
else:
print("Coordinates not found.")