Gestion de apis
This commit is contained in:
parent
30c4f728fb
commit
5202b768c5
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue