* TMW // TMW 7-DAY FORECAST WIDGET JAVASCRIPT
(function() {
// --- Configuration ---
// !!! IMPORTANT: REPLACE 'YOUR_API_KEY' with a valid key.
const API_KEY = 'YOUR_API_KEY';
const LAT = 41.7606; // Aurora, IL Latitude
const LON = -88.3201; // Aurora, IL Longitude
// API Endpoint for 7-day forecast (using OpenWeatherMap One Call API)
const URL = `https://api.openweathermap.org/data/2.5/onecall?lat=${LAT}&lon=${LON}&units=imperial&exclude=minutely,hourly,current,alerts&appid=${API_KEY}`;
const container = document.getElementById('tmw-forecast-banner');
if (!container || API_KEY === 'YOUR_API_KEY') {
console.error("TMW Forecast Error: Missing container ID or API Key not set.");
return;
}
fetch(URL)
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
})
.then(data => {
container.innerHTML = ''; // Clear the "Loading..." message
const forecastData = data.daily.slice(0, 7); // Get next 7 days
forecastData.forEach((day, index) => {
const date = new Date(day.dt * 1000);
// Display 'Today' for the first day, otherwise show the short day name
const dayName = index === 0 ? 'TODAY' : date.toLocaleDateString('en-US', { weekday: 'short' }).toUpperCase();
const high = Math.round(day.temp.max);
const low = Math.round(day.temp.min);
// Use the main weather condition text for the display
const condition = day.weather[0].main;
const iconCode = day.weather[0].icon;
// Card HTML structure
const card = `
${dayName}
${high}°
${low}°
`;
container.innerHTML += card;
});
})
.catch(error => {
container.innerHTML = '
Forecast Data Error. Check API Key and Log.
';
console.error('TMW Forecast Load Error:', error);
});
})();