aboutsummaryrefslogtreecommitdiff
path: root/weather-manager.js
diff options
context:
space:
mode:
authorMark Powers <markppowers0@gmail.com>2020-09-05 14:48:11 -0500
committerMark Powers <markppowers0@gmail.com>2020-09-05 14:48:11 -0500
commitad244411564f5563bc6f10a65833f4225698bdf5 (patch)
treed77725f503239902a41da96c3e9962681314b20c /weather-manager.js
parent8196c21f3af4b8085bb64d032ae1ea32a8218336 (diff)
Refactor forecast, add forecast styles
Diffstat (limited to 'weather-manager.js')
-rw-r--r--weather-manager.js20
1 files changed, 16 insertions, 4 deletions
diff --git a/weather-manager.js b/weather-manager.js
index 941c8cc..602e584 100644
--- a/weather-manager.js
+++ b/weather-manager.js
@@ -26,12 +26,24 @@ function loadWeather() {
}, "")
}
}
-if(!window.localStorage.weather){
+let fetchWeather = true;
+if(window.localStorage.weather_date){
+ let last_update = new Date(Date.parse(window.localStorage.weather_date))
+ let diff = new Date() - last_update;
+ // If one hour difference don't fetch
+ if(diff / (1000 * 60 * 60) < 1) {
+ fetchWeather = false;
+ }
+}
+
+if(fetchWeather){
fetch(`https://api.openweathermap.org/data/2.5/onecall?lat=${LAT}&lon=${LON}&APPID=${OPEN_WEATHER_API_KEY}&units=${WEATHER_UNITS}&exclude=hourly,minutely`)
.then(response => response.json())
.then(data => {
- console.log(data)
+ window.localStorage.weather_date = new Date();
window.localStorage.weather = JSON.stringify(data);
+ loadWeather()
});
-}
-loadWeather() \ No newline at end of file
+} else {
+ loadWeather()
+}