Tiempo

<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <title>Tiempo y Calidad del Aire</title>
</head>
<body>
    <h1>Información Meteorológica</h1>
    <p id="hora"></p>
    <p id="temperatura"></p>
    <p id="aire"></p>

    <script>
        const apiKey = "TU_API_KEY"; // Reemplaza con tu clave real
        const ciudad = "Murcia"; // Cambia por tu ubicación

        // Mostrar la hora actual
        function actualizarHora() {
            document.getElementById("hora").innerText = "Hora actual: " + new Date().toLocaleTimeString();
        }
        setInterval(actualizarHora, 1000);

        // Obtener datos de clima
        async function obtenerClima() {
            const url = `https://api.openweathermap.org/data/2.5/weather?q=${ciudad}&units=metric&appid=${apiKey}`;
            const respuesta = await fetch(url);
            const datos = await respuesta.json();
            document.getElementById("temperatura").innerText = `Temperatura: ${datos.main.temp}°C`;
        }

        // Obtener calidad del aire
        async function obtenerCalidadAire() {
            const url = `https://api.openweathermap.org/data/2.5/air_pollution?lat=37.98&lon=-1.13&appid=${apiKey}`;
            const respuesta = await fetch(url);
            const datos = await respuesta.json();
            document.getElementById("aire").innerText = `Índice de calidad del aire: ${datos.list[0].main.aqi}`;
        }

        obtenerClima();
        obtenerCalidadAire();
    </script>
</body>
</html>