Skip to content

Instantly share code, notes, and snippets.

@Proteusiq
Created December 14, 2025 17:56
Show Gist options
  • Select an option

  • Save Proteusiq/52e33155b6d9ca0f81720afe77a4cdfd to your computer and use it in GitHub Desktop.

Select an option

Save Proteusiq/52e33155b6d9ca0f81720afe77a4cdfd to your computer and use it in GitHub Desktop.
tools
import httpx
def get_coordinates(query: str) -> tuple[float, float]:
"""Return (latitude, longitude) for a given address in Denmark query."""
base_url = "https://nominatim.openstreetmap.org"
params = {
"q": query,
"format": "json",
"polygon_kml": 1,
"addressdetails": 1,
}
headers = {"User-Agent": "Prayson Daniel"}
with httpx.Client(base_url=base_url, headers=headers) as client:
response = client.get("/search", params=params)
response.raise_for_status()
results, *_ = response.json()
return float(results["lat"]), float(results["lon"])
def get_dmi_weather(latitude: float, longitude: float) -> str:
"""Return DMI weather for given latitude/longitude."""
LOC_URL = "https://www.dmi.dk/NinJo2DmiDk/ninjo2dmidk"
WEATHER_URL = "https://www.dmi.dk/dmidk_byvejrWS/rest/json/id"
loc_params = {
"cmd": "llj",
"hrs": 24,
"lon": longitude,
"lat": latitude,
}
with httpx.Client() as client:
loc_resp = client.get(LOC_URL, params=loc_params)
loc_resp.raise_for_status()
location_id = loc_resp.json().get("id")
if not location_id:
raise ValueError(
f"Could not resolve DMI location ID for ({latitude}, {longitude})"
)
weather_resp = client.get(f"{WEATHER_URL}/{location_id}")
weather_resp.raise_for_status()
report: str = weather_resp.json().get("regionalForecast").get("weatherForecast")
return report
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment