b l o g g i n s p a c e wiki
Difference between revisions of "Current Weather"
Jump to navigation
Jump to search
| Line 24: | Line 24: | ||
| <html><iframe src="https://wttr.in/Elizabethtown,Pennsylvania?u" width="900" height="580" style="border: none;"></iframe></html> | | <html><iframe src="https://wttr.in/Elizabethtown,Pennsylvania?u" width="900" height="580" style="border: none;"></iframe></html> | ||
|} | |} | ||
<html> | |||
<div id="weather-div" style="padding: 20px; background: #f0f8ff; border-radius: 10px; max-width: 300px; margin: 20px auto; text-align: center; font-family: Arial;"> | |||
<h3>Current Weather in Durham, NC</h3> | |||
<p id="temp">--°F</p> | |||
<p id="condition">--</p> | |||
<p id="updated">Loading...</p> | |||
</div> | |||
<script> | |||
const apiKey = 'YOUR_OPENWEATHERMAP_API_KEY'; // Replace with your key | |||
const city = 'Durham,NC,US'; // Or 'Chicago,IL,US' etc. | |||
const weatherDiv = document.getElementById('weather-div'); | |||
async function updateWeather() { | |||
try { | |||
const response = await fetch( | |||
`https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=${apiKey}&units=imperial` | |||
); | |||
const data = await response.json(); | |||
if (data.main) { | |||
document.getElementById('temp').textContent = `${Math.round(data.main.temp)}°F`; | |||
document.getElementById('condition').textContent = data.weather[0].description; | |||
document.getElementById('updated').textContent = `Updated: ${new Date().toLocaleTimeString()}`; | |||
} else { | |||
weatherDiv.innerHTML += '<p style="color:red;">Error loading weather</p>'; | |||
} | |||
} catch (error) { | |||
console.error('Weather fetch error:', error); | |||
} | |||
} | |||
// Run immediately on page load | |||
updateWeather(); | |||
// Then update every 4 hours (4 * 60 * 60 * 1000 = 14400000 ms) | |||
setInterval(updateWeather, 14400000); | |||
</script> | |||
</html> | |||
{{W}} | {{W}} | ||
[[Category:Help]] | [[Category:Help]] | ||
Revision as of 00:51, 14 January 2026
Weather?
⛅ Fort Wayne 🌪️ Toledo ⛈️ Columbus ⚡ Elizabethtown 🌨️ Tuscaloosa 🌩️ New York ☀️ Philly 🌤️ Ann Arbor ⛅ State College 🌪️ Norman ⛈️ New Orleans ⛈️ Atlanta ⚡ Durham 🌨️ Los Angeles ☀️ Seattle 🌤️ Boston ⛈️ Houston 🌨️ San Diego 🌤️
Fort Wayne, Indiana
Toledo, Ohio
Columbus, Ohio
Elizabethtown, Pennsylvania
Current Weather in Durham, NC
--°F
--
Loading...
Weather?
⛅ Fort Wayne 🌪️ Toledo ⛈️ Columbus ⚡ Elizabethtown 🌨️ Tuscaloosa 🌩️ New York ☀️ Philly 🌤️ Ann Arbor ⛅ State College 🌪️ Norman ⛈️ New Orleans ⛈️ Atlanta ⚡ Durham 🌨️ Los Angeles ☀️ Seattle 🌤️ Boston ⛈️ Houston 🌨️ San Diego 🌤️