import { fetchWeatherApi } from "openmeteo"; export async function getWeather() { const params = { latitude: 25.0772, longitude: 55.3093, current: ["temperature_2m", "wind_direction_180m", "wind_speed_180m"], timeformat: "unixtime", wind_speed_unit: "ms", }; const url = "https://api.open-meteo.com/v1/forecast"; const responses = await fetchWeatherApi(url, params); // Helper function to form time ranges // Process first location. Add a for-loop for multiple locations or weather models const response = responses[0]; // Attributes for timezone and location const utcOffsetSeconds = response.utcOffsetSeconds(); const current = response.current()!; // Note: The order of weather variables in the URL query and the indices below need to match! const weatherData = { current: { time: new Date((Number(current.time()) + utcOffsetSeconds) * 1000), temperature2m: current.variables(0)!.value(), windDirection180m: +current.variables(1)!.value().toFixed(2), windSpeed180m: +current.variables(2)!.value().toFixed(2), }, }; return weatherData.current; }