Spaces:
Sleeping
Sleeping
Download src/utils/location.py from jayanth-2005/1: direct link, hf CLI and curl.
- Browser
- Download file 644 Bytes
-
https://huggingface.co/spaces/jayanth-2005/1/resolve/main/src/utils/location.py
- Command line
-
hf download hf://spaces/jayanth-2005/1/src/utils/location.py
-
curl -L -o location.py https://huggingface.co/spaces/jayanth-2005/1/resolve/main/src/utils/location.py
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 | |