diff --git a/eltiempo/js/codigo.js b/eltiempo/js/codigo.js index 4532ef4..b359faf 100644 --- a/eltiempo/js/codigo.js +++ b/eltiempo/js/codigo.js @@ -1,3 +1,6 @@ +// API URL absoluta +const API_URL = "https://aplicacionesdevanguardia.es/eltiempo/servidor/weather-hoy.php?ciudad=madrid"; + /* ============================================== FUNCIONES AUXILIARES ============================================== */ @@ -146,9 +149,6 @@ async function updateSunCard(lat, lon) { /* ============================================== TIEMPO ACTUAL ============================================== */ -/* ============================================== - TIEMPO ACTUAL (CORREGIDO) -============================================== */ async function getWeather(position) { const lat = position.coords.latitude; const lon = position.coords.longitude; diff --git a/eltiempo/js/estadisticas.js b/eltiempo/js/estadisticas.js index 2b061d0..ac5377b 100644 --- a/eltiempo/js/estadisticas.js +++ b/eltiempo/js/estadisticas.js @@ -1,5 +1,6 @@ // API URL absoluta const API_URL = "https://aplicacionesdevanguardia.es/eltiempo/servidor/api-weather.php?ciudad=madrid"; +const API_URL_TODAY = "https://aplicacionesdevanguardia.es/eltiempo/servidor/weather-hoy.php?ciudad=madrid"; // ==================== // Helper @@ -36,6 +37,24 @@ async function loadStats() { } } +async function loadStatsToday() { + try { + const response = await fetch(API_URL_TODAY); + if (!response.ok) throw new Error("Error cargando datos: " + response.status); + + const data = await response.json(); + + if (!data || !data.length) throw new Error("Datos vacíos"); + + renderLastData(data); + renderMonthStats(data); + renderTrend(data); + } catch (err) { + console.error(err); + $("stats-location").textContent = "Error cargando datos"; + } +} + // ==================== // Último dato // ==================== @@ -128,17 +147,20 @@ function renderTrend(data) { document.addEventListener("DOMContentLoaded", () => { updateMonthHeader(); loadStats(); + loadStatsToday(); $("prev-month").addEventListener("click", () => { selectedMonth = (selectedMonth + 11) % 12; updateMonthHeader(); loadStats(); + loadStatsToday(); }); $("next-month").addEventListener("click", () => { selectedMonth = (selectedMonth + 1) % 12; updateMonthHeader(); loadStats(); + loadStatsToday(); }); $("year").textContent = new Date().getFullYear(); diff --git a/eltiempo/servidor/api-weather.php b/eltiempo/servidor/api-weather.php index 3c4d150..5845906 100755 --- a/eltiempo/servidor/api-weather.php +++ b/eltiempo/servidor/api-weather.php @@ -54,7 +54,7 @@ $stmt = $conn->prepare(" WHERE DATE(fecha) >= '2024-10-01' AND ciudad LIKE CONCAT('%', ?, '%') GROUP BY DATE(fecha) - ORDER BY DATE(fecha) + ORDER BY DATE(fecha); "); if (!$stmt) {