MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / current_weather

Function current_weather

web_programming/current_weather.py:19–41  ·  view source on GitHub ↗

>>> current_weather("location") Traceback (most recent call last): ... ValueError: No API keys provided or no valid data returned.

(location: str)

Source from the content-addressed store, hash-verified

17
18
19def 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
44if __name__ == "__main__":

Callers 1

current_weather.pyFile · 0.85

Calls 3

jsonMethod · 0.80
getMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected