`; } return html; } async function fetchWeather(loc) { const params = new URLSearchParams({ latitude: loc.lat, longitude: loc.lon, timezone: "America/New_York", temperature_unit: "fahrenheit", wind_speed_unit: "mph", forecast_days: "7", current: "temperature_2m,apparent_temperature,weather_code,wind_speed_10m,wind_direction_10m", hourly: "temperature_2m,apparent_temperature,precipitation_probability,weather_code,wind_speed_10m", daily: "weather_code,temperature_2m_max,temperature_2m_min,apparent_temperature_max,precipitation_probability_max,wind_speed_10m_max,wind_direction_10m_dominant" }); const url = "https://api.open-meteo.com/v1/forecast?" + params.toString(); const response = await fetch(url); if (!response.ok) { throw new Error("Weather request failed"); } return response.json(); } async function loadWeather() { try { const [marco, naples] = await Promise.all([ fetchWeather(locations.marco), fetchWeather(locations.naples) ]); const marcoHigh = Math.round(marco.daily.temperature_2m_max[0]); const naplesHigh = Math.round(naples.daily.temperature_2m_max[0]); const rainChance = Math.max( marco.daily.precipitation_probability_max[0] || 0, naples.daily.precipitation_probability_max[0] || 0 ); const heat = Math.round( Math.max( marco.daily.apparent_temperature_max[0], naples.daily.apparent_temperature_max[0] ) ); const windSpeed = Math.round( Math.max( marco.daily.wind_speed_10m_max[0], naples.daily.wind_speed_10m_max[0] ) ); const windDirection = cardinal( marco.daily.wind_direction_10m_dominant[0] ); const morning = getHours(marco, 6, 12); const afternoon = getHours(marco, 12, 18); const tonight = getHours(marco, 18, 24); const daylight = getHours(marco, 6, 20); const now = new Date(); const updateText = now.toLocaleTimeString( "en-US", { hour: "numeric", minute: "2-digit" } ); document.getElementById( "minn-weather-content" ).innerHTML = `
Marco Island
${marcoHigh}°F
Rain Chances
☔ ${rainChance}%
💨 Winds: ${windDirection} up to ${windSpeed} mph
🌅 Morning
${summarizePeriod(morning)}
☀️ Afternoon
${summarizePeriod(afternoon)}
🌙 Tonight
${summarizePeriod(tonight)}
⭐ Best Outdoor Window: ${bestOutdoorWindow(daylight)}
📅 Marco Island & Naples 7-Day Outlook
${buildSevenDay(marco, naples)}
Updated ${updateText} • Forecast data: Open-Meteo
`; } catch(error) { document.getElementById( "minn-weather-content" ).innerHTML = `
Weather information is temporarily unavailable.
`; console.error(error); } } loadWeather(); /* automatically refresh every 30 minutes */ setInterval(loadWeather, 1800000); })();