{"id":17,"date":"2026-10-25T19:08:57","date_gmt":"2026-10-25T19:08:57","guid":{"rendered":"https:\/\/jordiferri.com\/?page_id=17"},"modified":"2026-10-25T19:35:06","modified_gmt":"2026-10-25T19:35:06","slug":"panel-en-vivo","status":"publish","type":"page","link":"https:\/\/jordiferri.com\/","title":{"rendered":"Panel en Vivo"},"content":{"rendered":"\n<!DOCTYPE html>\n<html lang=\"es\">\n<head>\n    <meta charset=\"UTF-8\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    <title>Predicci\u00f3n del Tiempo &#8211; 7 D\u00edas<\/title>\n    <!-- Tailwind CSS y FontAwesome -->\n    <script src=\"https:\/\/cdn.tailwindcss.com\"><\/script>\n    <link rel=\"stylesheet\" href=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/font-awesome\/6.4.0\/css\/all.min.css\">\n    <style>\n        body { background-color: #0f172a; color: #f8fafc; font-family: system-ui, -apple-system, sans-serif; }\n        .glass-card { background: rgba(30, 41, 59, 0.85); backdrop-filter: blur(12px); border: 1px solid rgba(255, 255, 255, 0.1); }\n    <\/style>\n<\/head>\n<body class=\"min-h-screen p-4 md:p-8 flex items-center justify-center\">\n\n    <div class=\"max-w-2xl w-full\">\n        <!-- CONTENEDOR \u00daNICO DEL TIEMPO -->\n        <div class=\"glass-card rounded-3xl p-6 md:p-8 shadow-2xl border-t-4 border-emerald-400\">\n            \n            <!-- Encabezado y Buscador -->\n            <div class=\"text-center mb-6\">\n                <h1 class=\"text-2xl md:text-3xl font-extrabold text-white flex items-center justify-center gap-3\">\n                    <i class=\"fa-solid fa-cloud-sun text-emerald-400\"><\/i> El Tiempo (7 D\u00edas)\n                <\/h1>\n                <p class=\"text-slate-400 text-sm mt-1\">Introduce una localidad o C\u00f3digo Postal para ver la predicci\u00f3n semanal<\/p>\n                \n                <form id=\"searchForm\" class=\"mt-5 flex justify-center items-center gap-2 max-w-md mx-auto\">\n                    <input type=\"text\" id=\"busquedaInput\" placeholder=\"Ej: Alcoy o 03802\" class=\"w-full px-4 py-2.5 rounded-xl bg-slate-800 border border-slate-700 text-white focus:outline-none focus:border-emerald-400 text-center font-medium placeholder:text-slate-500\">\n                    <button type=\"submit\" class=\"bg-emerald-500 hover:bg-emerald-600 text-slate-950 font-bold px-5 py-2.5 rounded-xl transition-colors shrink-0 cursor-pointer\">\n                        Buscar\n                    <\/button>\n                <\/form>\n            <\/div>\n\n            <!-- Cabecera de ubicaci\u00f3n -->\n            <div class=\"text-center border-b border-slate-700\/60 pb-4 mb-6\">\n                <h2 id=\"ubicacionNombre\" class=\"text-xl font-bold text-emerald-300 flex items-center justify-center gap-2\">\n                    <i class=\"fa-solid fa-map-location-dot\"><\/i> Espa\u00f1a (Selecciona una ubicaci\u00f3n)\n                <\/h2>\n            <\/div>\n\n            <!-- Lista de los 7 d\u00edas -->\n            <div id=\"forecastContainer\" class=\"space-y-3\">\n                <div class=\"text-center py-8 text-slate-400\">\n                    <i class=\"fa-solid fa-signs-post text-3xl mb-2 text-slate-600 block\"><\/i>\n                    Escribe una ciudad o c\u00f3digo postal y pulsa <strong>Buscar<\/strong> para consultar el tiempo.\n                <\/div>\n            <\/div>\n            \n        <\/div>\n    <\/div>\n\n    <script>\n        \/\/ Controlar el evento submit del formulario de forma limpia\n        document.getElementById('searchForm').addEventListener('submit', function(e) {\n            e.preventDefault();\n            buscarUbicacion();\n        });\n\n        function obtenerIconoYTextoClima(code) {\n            if (code === 0) return { icon: 'fa-sun text-amber-400', texto: 'Despejado' };\n            if (code >= 1 && code <= 3) return { icon: 'fa-cloud-sun text-amber-200', texto: 'Parcialmente nublado' };\n            if (code === 45 || code === 48) return { icon: 'fa-smog text-slate-400', texto: 'Niebla' };\n            if (code >= 51 && code <= 67) return { icon: 'fa-cloud-rain text-blue-400', texto: 'Lluvia ligera' };\n            if (code >= 71 && code <= 77) return { icon: 'fa-snowflake text-cyan-200', texto: 'Nieve' };\n            if (code >= 80 && code <= 82) return { icon: 'fa-cloud-showers-heavy text-blue-500', texto: 'Chubascos' };\n            if (code >= 95) return { icon: 'fa-bolt text-yellow-400', texto: 'Tormenta' };\n            return { icon: 'fa-cloud text-slate-300', texto: 'Nublado' };\n        }\n\n        async function buscarUbicacion() {\n            const query = document.getElementById('busquedaInput').value.trim();\n            if(!query) {\n                alert(\"Por favor, introduce una localidad o un C\u00f3digo Postal.\");\n                return;\n            }\n\n            const container = document.getElementById('forecastContainer');\n            container.innerHTML = `<p class=\"text-center text-slate-400 py-8\"><i class=\"fa-solid fa-spinner fa-spin\"><\/i> Buscando \"${query}\"...<\/p>`;\n\n            let lat, lon, nombreZona;\n\n            try {\n                \/\/ Caso 1: Si es un C\u00f3digo Postal de 5 d\u00edgitos\n                if (\/^\\d{5}$\/.test(query)) {\n                    const resZip = await fetch(`https:\/\/api.zippopotam.us\/es\/${query}`);\n                    if (resZip.ok) {\n                        const dataZip = await resZip.json();\n                        const place = dataZip.places[0];\n                        lat = place.latitude;\n                        lon = place.longitude;\n                        nombreZona = `${place['place name']} (${place['state']}) - CP ${query}`;\n                    } else {\n                        throw new Error(\"CP no encontrado\");\n                    }\n                } \n                \/\/ Caso 2: B\u00fasqueda por Nombre de Ciudad\/Localidad\n                else {\n                    const resGeo = await fetch(`https:\/\/geocoding-api.open-meteo.com\/v1\/search?name=${encodeURIComponent(query)}&count=1&language=es&format=json`);\n                    const dataGeo = await resGeo.json();\n\n                    if (dataGeo.results && dataGeo.results.length > 0) {\n                        const res = dataGeo.results[0];\n                        lat = res.latitude;\n                        lon = res.longitude;\n                        const region = res.admin1 ? ` (${res.admin1})` : '';\n                        const pais = res.country ? `, ${res.country}` : '';\n                        nombreZona = `${res.name}${region}${pais}`;\n                    } else {\n                        throw new Error(\"Localidad no encontrada\");\n                    }\n                }\n\n                cargarTiempo7Dias(lat, lon, nombreZona);\n\n            } catch (error) {\n                container.innerHTML = `<p class=\"text-center text-red-400 py-8\">No se encontraron resultados para \"${query}\". Intenta especificar con m\u00e1s detalle.<\/p>`;\n                document.getElementById('ubicacionNombre').innerHTML = `<i class=\"fa-solid fa-triangle-exclamation text-amber-400\"><\/i> Sin resultados`;\n            }\n        }\n\n        async function cargarTiempo7Dias(lat, lon, nombreZona) {\n            document.getElementById('ubicacionNombre').innerHTML = `<i class=\"fa-solid fa-location-dot\"><\/i> ${nombreZona}`;\n            const container = document.getElementById('forecastContainer');\n            \n            try {\n                const res = await fetch(`https:\/\/api.open-meteo.com\/v1\/forecast?latitude=${lat}&longitude=${lon}&daily=weather_code,temperature_2m_max,temperature_2m_min,precipitation_sum&timezone=auto`);\n                if (!res.ok) throw new Error(\"Error en Open-Meteo\");\n                \n                const data = await res.json();\n                const daily = data.daily;\n                let htmlContent = '';\n\n                for (let i = 0; i < daily.time.length; i++) {\n                    const fechaRaw = daily.time[i];\n                    const fechaObj = new Date(fechaRaw + 'T00:00:00');\n                    \n                    const opcionesDia = { weekday: 'long', day: 'numeric', month: 'short' };\n                    let diaNombre = fechaObj.toLocaleDateString('es-ES', opcionesDia);\n                    diaNombre = diaNombre.charAt(0).toUpperCase() + diaNombre.slice(1);\n\n                    const tempMax = Math.round(daily.temperature_2m_max[i]);\n                    const tempMin = Math.round(daily.temperature_2m_min[i]);\n                    const lluvia = daily.precipitation_sum[i];\n                    const infoClima = obtenerIconoYTextoClima(daily.weather_code[i]);\n\n                    htmlContent += `\n                        <div class=\"flex items-center justify-between p-3.5 bg-slate-800\/60 rounded-xl hover:bg-slate-800 transition-colors border border-slate-700\/40\">\n                            <div class=\"flex items-center gap-3\">\n                                <i class=\"fa-solid ${infoClima.icon} text-2xl w-8 text-center\"><\/i>\n                                <div>\n                                    <div class=\"font-semibold text-white text-sm md:text-base\">${diaNombre}<\/div>\n                                    <div class=\"text-xs text-slate-400\">${infoClima.texto}<\/div>\n                                <\/div>\n                            <\/div>\n                            <div class=\"flex items-center gap-4 text-right\">\n                                ${lluvia > 0 ? `<span class=\"text-xs text-cyan-400 font-medium\"><i class=\"fa-solid fa-droplet\"><\/i> ${lluvia} mm<\/span>` : ''}\n                                <div class=\"text-sm font-bold\">\n                                    <span class=\"text-amber-400\">${tempMax}\u00b0<\/span> \n                                    <span class=\"text-slate-500 font-normal\">\/<\/span> \n                                    <span class=\"text-blue-400\">${tempMin}\u00b0<\/span>\n                                <\/div>\n                            <\/div>\n                        <\/div>\n                    `;\n                }\n\n                container.innerHTML = htmlContent;\n\n            } catch (e) {\n                container.innerHTML = `<p class=\"text-center text-red-400 py-8\">Error al conectar con el servidor meteorol\u00f3gico.<\/p>`;\n            }\n        }\n    <\/script>\n<\/body>\n<\/html>\n","protected":false},"excerpt":{"rendered":"<p>Predicci\u00f3n del Tiempo &#8211; 7 D\u00edas El Tiempo (7 D\u00edas) Introduce una localidad o C\u00f3digo Postal para ver la predicci\u00f3n semanal Buscar Espa\u00f1a (Selecciona una ubicaci\u00f3n) Escribe una ciudad o c\u00f3digo postal y pulsa Buscar para consultar el tiempo.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-17","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/jordiferri.com\/index.php?rest_route=\/wp\/v2\/pages\/17","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jordiferri.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/jordiferri.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/jordiferri.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jordiferri.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=17"}],"version-history":[{"count":6,"href":"https:\/\/jordiferri.com\/index.php?rest_route=\/wp\/v2\/pages\/17\/revisions"}],"predecessor-version":[{"id":23,"href":"https:\/\/jordiferri.com\/index.php?rest_route=\/wp\/v2\/pages\/17\/revisions\/23"}],"wp:attachment":[{"href":"https:\/\/jordiferri.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=17"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}