-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathweather.js
37 lines (32 loc) · 1.24 KB
/
weather.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function weatherBallon( cityID ) {
//Edit the line below with your city-id and api-key and replace the fetch after the comments
//fetch('https://api.openweathermap.org/data/2.5/weather?id= CITY-ID &appid= API-KEY ')
fetch('https://api.openweathermap.org/data/2.5/weather?id=1261481&appid=d19b217fed0cd976b0612b2f0c323503')
.then(function(resp) { return resp.json() }) // Convert data to json
.then(function(data) {
drawWeather(data);
})
.catch(function() {
// catch any errors
});
}
function drawWeather( d ) {
var celcius = Math.round(parseFloat(d.main.temp)-273.15);
var fahrenheit = Math.round(((parseFloat(d.main.temp)-273.15)*1.8)+32);
var description = d.weather[0].description;
document.getElementById('description').innerHTML = description;
document.getElementById('temp').innerHTML = celcius + '°';
document.getElementById('location').innerHTML = d.name;
if( description.indexOf('rain') > 0 ) {
document.body.className = 'rainy';
} else if( description.indexOf('cloud') > 0 ) {
document.body.className = 'cloudy';
} else if( description.indexOf('sunny') > 0 ) {
document.body.className = 'sunny';
} else {
document.body.className = 'clear';
}
}
window.onload = function() {
weatherBallon( 6167865 );
}