1 / src /utils /location.py
jayanth-2005's picture
Upload 3 files
50321e5 verified
Raw History Blame Contribute Delete
644 Bytes
"""Location related functionality for BharatPlay."""
import requests
import urllib3
def get_ip_location():
"""Get user's location from IP address using ipinfo.io."""
try:
# Disable SSL warning
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
response = requests.get("https://ipinfo.io/json", verify=False)
data = response.json()
loc = data.get("loc")
if loc:
lat_str, lon_str = loc.split(",")
return float(lat_str), float(lon_str)
except Exception as e:
print(f"Error getting location: {e}")
return None, None