mirror of https://github.com/espruino/BangleApps
Save minimal weather data and limit weather update frequency
parent
5c3b742a42
commit
3371f86bb5
|
@ -324,19 +324,26 @@ function setWeather() {
|
|||
}
|
||||
|
||||
function readWeather() {
|
||||
var weatherData = require("Storage").readJSON('weather.json', true);
|
||||
if (weatherData !== undefined) {
|
||||
if (weatherData.weather.time > data.time) {
|
||||
data = weatherData.weather;
|
||||
require("Storage").write('mtnclock.json', data);
|
||||
}
|
||||
var weatherJson = require("Storage").readJSON('weather.json', 1);
|
||||
// save updated weather data if available and it has been an hour since last updated
|
||||
if (weatherJson !== undefined && (data.time === undefined || (data.time + 3600000) < weatherJson.weather.time)) {
|
||||
data = {
|
||||
time: weatherJson.weather.time,
|
||||
temp: weatherJson.weather.temp,
|
||||
code: weatherJson.weather.code
|
||||
};
|
||||
require("Storage").writeJSON('mtnclock.json', data);
|
||||
}
|
||||
}
|
||||
|
||||
const _GB = global.GB;
|
||||
global.GB = (event) => {
|
||||
if (event.t==="weather") {
|
||||
data = event;
|
||||
data = {
|
||||
temp: event.temp,
|
||||
code: event.code,
|
||||
time: Date.now()
|
||||
};
|
||||
require("Storage").write('mtnclock.json', event);
|
||||
setWeather();
|
||||
}
|
||||
|
@ -357,5 +364,6 @@ function queueDraw() {
|
|||
}
|
||||
|
||||
queueDraw();
|
||||
readWeather();
|
||||
setWeather();
|
||||
Bangle.setUI("clock");
|
||||
|
|
Loading…
Reference in New Issue