Dharsan Decodes Data

(Eng) S5 E4.1. Python essentials for DE

pip install requests

import requests # Telling Python we want to use this power-up

# The "Waiter's" Address (A free API for current weather)

url = "https://api.open-meteo.com/v1/forecast?latitude=13.08&longitude=80.27¤t_weather=true"

# 1. Send the request

response = requests.get(url)

# 2. Convert the "mess" into a Python Dictionary

data = response.json()

# 3. Dig into the Dictionary to find the temperature

# (Based on the JSON structure the API provides)

current_temp = data["current_weather"]["temperature"]

print(f"The current temperature in Chennai is {current_temp}°C")