1
File size: 644 Bytes
50321e5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
"""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