Created
December 14, 2025 17:56
-
-
Save Proteusiq/52e33155b6d9ca0f81720afe77a4cdfd to your computer and use it in GitHub Desktop.
tools
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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