Gestion de apis

This commit is contained in:
Tatiana Villa 2026-02-06 10:20:01 +01:00
parent 30c4f728fb
commit 5202b768c5
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
============================================== */
@ -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;

View File

@ -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();

View File

@ -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) {