Merge branch 'main' of github.com:tatvil/aplicacionesdevanguardia

This commit is contained in:
Tatiana Villa 2026-02-06 09:20:20 +00:00
commit f6317c5d32
3 changed files with 26 additions and 4 deletions

View File

@ -1,3 +1,6 @@
// API URL absoluta
const API_URL = "https://aplicacionesdevanguardia.es/eltiempo/servidor/weather-hoy.php?ciudad=madrid";
/* ============================================== /* ==============================================
FUNCIONES AUXILIARES FUNCIONES AUXILIARES
============================================== */ ============================================== */
@ -146,9 +149,6 @@ async function updateSunCard(lat, lon) {
/* ============================================== /* ==============================================
TIEMPO ACTUAL TIEMPO ACTUAL
============================================== */ ============================================== */
/* ==============================================
TIEMPO ACTUAL (CORREGIDO)
============================================== */
async function getWeather(position) { async function getWeather(position) {
const lat = position.coords.latitude; const lat = position.coords.latitude;
const lon = position.coords.longitude; const lon = position.coords.longitude;

View File

@ -1,5 +1,6 @@
// API URL absoluta // API URL absoluta
const API_URL = "https://aplicacionesdevanguardia.es/eltiempo/servidor/api-weather.php?ciudad=madrid"; 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 // 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 // Último dato
// ==================== // ====================
@ -128,17 +147,20 @@ function renderTrend(data) {
document.addEventListener("DOMContentLoaded", () => { document.addEventListener("DOMContentLoaded", () => {
updateMonthHeader(); updateMonthHeader();
loadStats(); loadStats();
loadStatsToday();
$("prev-month").addEventListener("click", () => { $("prev-month").addEventListener("click", () => {
selectedMonth = (selectedMonth + 11) % 12; selectedMonth = (selectedMonth + 11) % 12;
updateMonthHeader(); updateMonthHeader();
loadStats(); loadStats();
loadStatsToday();
}); });
$("next-month").addEventListener("click", () => { $("next-month").addEventListener("click", () => {
selectedMonth = (selectedMonth + 1) % 12; selectedMonth = (selectedMonth + 1) % 12;
updateMonthHeader(); updateMonthHeader();
loadStats(); loadStats();
loadStatsToday();
}); });
$("year").textContent = new Date().getFullYear(); $("year").textContent = new Date().getFullYear();

View File

@ -54,7 +54,7 @@ $stmt = $conn->prepare("
WHERE DATE(fecha) >= '2024-10-01' WHERE DATE(fecha) >= '2024-10-01'
AND ciudad LIKE CONCAT('%', ?, '%') AND ciudad LIKE CONCAT('%', ?, '%')
GROUP BY DATE(fecha) GROUP BY DATE(fecha)
ORDER BY DATE(fecha) ORDER BY DATE(fecha);
"); ");
if (!$stmt) { if (!$stmt) {