Spaces:
Sleeping
Sleeping
Download gis.py from dldx/renewables-lcoe-api: direct link, hf CLI and curl.
- Browser
- Download file 858 Bytes
-
https://huggingface.co/spaces/dldx/renewables-lcoe-api/resolve/main/gis.py
- Command line
-
hf download hf://spaces/dldx/renewables-lcoe-api/gis.py
-
curl -L -o gis.py https://huggingface.co/spaces/dldx/renewables-lcoe-api/resolve/main/gis.py
858 Bytes
| import requests | |
| from dotenv import load_dotenv | |
| import os | |
| load_dotenv() | |
| def get_coordinates(address: str) -> dict: | |
| """Get the latitude and longitude of a given address using the OpenCage Geocoding API. | |
| Args: | |
| address (str): The address. | |
| Returns: | |
| dict: The latitude and longitude. | |
| """ | |
| LOCATIONIQ_API_KEY = os.getenv("LOCATIONIQ_API_KEY") | |
| res = requests.get(f"https://us1.locationiq.com/v1/search?key={LOCATIONIQ_API_KEY}&q={address}&format=json&limit=1") | |
| if res.status_code != 200: | |
| raise Exception(f"Error: {res.status_code}") | |
| data = res.json() | |
| if not data: | |
| raise Exception(f"No results found for address: {address}") | |
| data = data[0] | |
| return { | |
| "latitude": float(data["lat"]), | |
| "longitude": float(data["lon"]), | |
| "display_name": data["display_name"], | |
| } | |