Add OpenWeather API

This commit is contained in:
Tressley Cahill
2022-11-01 17:01:07 -04:00
parent 020d4b5fe8
commit 723d73e127
3 changed files with 40 additions and 6 deletions
+22 -5
View File
@@ -1,7 +1,24 @@
function dateTime () {
const date = new Date()
let today = date.toDateString()
let time = date.toLocaleTimeString()
document.getElementsByName('q')[0].placeholder = today + ' ' + time
setTimeout(dateTime, 1000)
const date = new Date();
let today = date.toDateString();
let time = date.toLocaleTimeString();
document.getElementById('date-time').innerHTML = '<p id="date">' + today + '</p><p id="time">' + time + '</p>';
setTimeout(dateTime, 1000);
}
function weatherBalloon(cityID) {
var apiKey = 'fad9628260a1bc2ebaaf85a7dfe800d0';
fetch('https://api.openweathermap.org/data/2.5/weather?id=' + cityID + '&appid=' + apiKey)
.then(function(resp) { return resp.json() })
.then(function(data) {
let tempK = parseFloat(data.main.temp);
let tempC = Math.round(tempK-273.15);
let tempF = Math.round((tempK-273.15)*1.8)+32;
document.getElementById('weather').innerHTML = '<p id="location">' + data.name + '</p><p id="details">' + data.weather[0].description + '<span class="separator">|</span>' + tempC + '&deg;C</p>';
});
}
function traichu() {
dateTime();
weatherBalloon(6254926);
}