`; } 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 response = await fetch( "https://api.open-meteo.com/v1/forecast?" + params.toString() ); if (!response.ok) { throw new Error("Weather request failed"); } return response.json(); } async function loadWeather() { try { const dataList = await Promise.all( locations.map(fetchWeather) ); const today = dataList[0].daily.time[0]; const cityCards = dataList.map((data,i) => { const current = data.current; const high = data.daily.temperature_2m_max[0]; const low = data.daily.temperature_2m_min[0]; const rain = data.daily.precipitation_probability_max[0]; return `
${locations[i].name}
${weatherIcon(current.weather_code)}
${fmt(current.temperature_2m,"°F")}
High ${fmt(high,"°")} / Low ${fmt(low,"°")}
${weatherText(current.weather_code)}
💧 Rain today: ${fmt(rain,"%")}
`; }).join(""); const rainChance = maximum(dataList.map(d => d.daily.precipitation_probability_max[0] )); const feelsLike = maximum(dataList.map(d => d.daily.apparent_temperature_max[0] )); const windSpeed = maximum(dataList.map(d => d.daily.wind_speed_10m_max[0] )); const regionalHigh = maximum(dataList.map(d => d.daily.temperature_2m_max[0] )); const regionalLow = minimum(dataList.map(d => d.daily.temperature_2m_min[0] )); const morning = dataList.flatMap(d => getHours(d,6,12,today) ); const afternoon = dataList.flatMap(d => getHours(d,12,18,today) ); const tonight = dataList.flatMap(d => getHours(d,18,24,today) ); const updateText = new Date().toLocaleString("en-US",{ timeZone:"America/New_York", month:"short", day:"numeric", hour:"numeric", minute:"2-digit", timeZoneName:"short" }); content.innerHTML = `
📍 Current Weather by City
${cityCards}
Regional High / Low
${fmt(regionalHigh,"°")} / ${fmt(regionalLow,"°")}
Rain Chances
☔ ${fmt(rainChance,"%")}
Max Feels Like
🌡️ ${fmt(feelsLike,"°F")}
💨 Regional Winds: Gust-free forecast wind speeds up to ${fmt(windSpeed," mph")} across the six cities.
🌅 Morning
${summarizePeriod(morning)}
☀️ Afternoon
${summarizePeriod(afternoon)}
🌙 Tonight
${summarizePeriod(tonight)}
⭐ Best Outdoor Window: ${bestOutdoorWindow(dataList,today)}
📅 Southwest Florida 7-Day Outlook
${buildSevenDay(dataList)}
Regional highs and lows represent the range across all six cities. Rain percentages show the highest forecast probability among them.
Updated ${updateText} • Forecast data: Open-Meteo
`; } catch(error) { content.innerHTML = `
Weather information is temporarily unavailable. Please try again shortly.
`; console.error("Southwest Florida weather:",error); } } loadWeather(); setInterval(loadWeather,1800000); })();