-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
21 lines (18 loc) · 838 Bytes
/
Copy pathscript.js
File metadata and controls
21 lines (18 loc) · 838 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const API_KEY = ""; // your API key from https://openweathermap.org/api
const CITY = ""; // your city
async function loadWeather() {
try {
const url = `https://api.openweathermap.org/data/2.5/weather?q=${CITY}&appid=${API_KEY}&units=metric&lang=en`;
const response = await fetch(url);
const data = await response.json();
document.getElementById("city").textContent = data.name;
document.getElementById("temp").textContent = Math.round(data.main.temp) + "°C";
document.getElementById("desc").textContent = data.weather[0].description;
} catch (e) {
document.getElementById("city").textContent = "error";
document.getElementById("temp").textContent = "--°C";
document.getElementById("desc").textContent = "failed to load";
}
}
loadWeather();
setInterval(loadWeather, 300000); // refresh 5 min