>>> current_weather("location") Traceback (most recent call last): ... ValueError: No API keys provided or no valid data returned.
(location: str)
| 17 | |
| 18 | |
| 19 | def current_weather(location: str) -> list[dict]: |
| 20 | """ |
| 21 | >>> current_weather("location") |
| 22 | Traceback (most recent call last): |
| 23 | ... |
| 24 | ValueError: No API keys provided or no valid data returned. |
| 25 | """ |
| 26 | weather_data = [] |
| 27 | if OPENWEATHERMAP_API_KEY: |
| 28 | params_openweathermap = {"q": location, "appid": OPENWEATHERMAP_API_KEY} |
| 29 | response_openweathermap = httpx.get( |
| 30 | OPENWEATHERMAP_URL_BASE, params=params_openweathermap, timeout=10 |
| 31 | ) |
| 32 | weather_data.append({"OpenWeatherMap": response_openweathermap.json()}) |
| 33 | if WEATHERSTACK_API_KEY: |
| 34 | params_weatherstack = {"query": location, "access_key": WEATHERSTACK_API_KEY} |
| 35 | response_weatherstack = httpx.get( |
| 36 | WEATHERSTACK_URL_BASE, params=params_weatherstack, timeout=10 |
| 37 | ) |
| 38 | weather_data.append({"Weatherstack": response_weatherstack.json()}) |
| 39 | if not weather_data: |
| 40 | raise ValueError("No API keys provided or no valid data returned.") |
| 41 | return weather_data |
| 42 | |
| 43 | |
| 44 | if __name__ == "__main__": |
no test coverage detected