import requests
API_KEY = "your_openweathermap_api_key"
BASE_URL = "http://api.openweathermap.org/data/2.5/weather"
def get_weather(city):
params = {"q": city, "appid": API_KEY, "units": "metric"}
response = requests.get(BASE_URL, params=params)
data = response.json()
if data.get("cod") == 200:
weather = data["weather"][0]["description"]
temperature = data["main"]["temp"]
speak(f"The weather in {city} is {weather} with a temperature of {temperature}°C.")
else:
speak("Sorry, I couldn't find the weather for that location.")
Here’s the full workflow: