const axios = require('axios'); const getWeather = async (latitude, longitude) => { try { const response = await axios.get('https://api.open-meteo.com/v1/forecast', { params: { latitude: latitude, longitude: longitude, current_weather: true, timezone: 'auto' } }); if (!response.data.current_weather) { throw new Error('Datos de clima no disponibles.'); } const weather = response.data.current_weather; return { temperature: weather.temperature, windspeed: weather.windspeed, winddirection: weather.winddirection, weathercode: weather.weathercode, time: weather.time }; } catch (error) { throw new Error(`Error al obtener el clima: ${error.message}`); } }; module.exports = { getWeather };