use weather codes if language is not English
parent
13f74e1542
commit
3e10fff373
|
|
@ -1,5 +1,5 @@
|
||||||
const w = require("weather");
|
const w = require("weather");
|
||||||
//const locale = require("locale");
|
const locale = require("locale");
|
||||||
|
|
||||||
// Weather icons from https://icons8.com/icon/set/weather/color
|
// Weather icons from https://icons8.com/icon/set/weather/color
|
||||||
function getSun() {
|
function getSun() {
|
||||||
|
|
@ -67,6 +67,33 @@ function chooseIcon(condition) {
|
||||||
return getPartSun;
|
return getPartSun;
|
||||||
} else return getErr;
|
} else return getErr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Choose weather icon to display based on weather conditition code
|
||||||
|
* https://openweathermap.org/weather-conditions#Weather-Condition-Codes-2
|
||||||
|
*/
|
||||||
|
function chooseIconByCode(code) {
|
||||||
|
const codeGroup = Math.round(code / 100);
|
||||||
|
switch (codeGroup) {
|
||||||
|
case 2: return getStorm;
|
||||||
|
case 3: return getRain;
|
||||||
|
case 5:
|
||||||
|
switch (code) {
|
||||||
|
case 511: return getSnow;
|
||||||
|
default: return getRain;
|
||||||
|
}
|
||||||
|
case 6: return getSnow;
|
||||||
|
case 7: return getPartSun;
|
||||||
|
case 8:
|
||||||
|
switch (code) {
|
||||||
|
case 800: return getSun;
|
||||||
|
case 804: return getCloud;
|
||||||
|
default: return getPartSun;
|
||||||
|
}
|
||||||
|
default: return getCloud;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*function condenseWeather(condition) {
|
/*function condenseWeather(condition) {
|
||||||
condition = condition.toLowerCase();
|
condition = condition.toLowerCase();
|
||||||
if (condition.includes("thunderstorm") ||
|
if (condition.includes("thunderstorm") ||
|
||||||
|
|
@ -143,8 +170,18 @@ const clock = new ClockFace({
|
||||||
//let cWea =(curr === "no data" ? "no data" : curr.txt);
|
//let cWea =(curr === "no data" ? "no data" : curr.txt);
|
||||||
let cTemp= (curr === "no data" ? 273 : curr.temp);
|
let cTemp= (curr === "no data" ? 273 : curr.temp);
|
||||||
// const temp = locale.temp(curr.temp - 273.15).match(/^(\D*\d*)(.*)$/);
|
// const temp = locale.temp(curr.temp - 273.15).match(/^(\D*\d*)(.*)$/);
|
||||||
|
|
||||||
|
if (locale == "en" || locale == "en_GB" || locale == "en_US") {
|
||||||
let w_icon = chooseIcon(curr.txt === undefined ? "no data" : curr.txt);
|
let w_icon = chooseIcon(curr.txt === undefined ? "no data" : curr.txt);
|
||||||
//let w_icon = chooseIcon(curr.txt);
|
} else {
|
||||||
|
// cannot use condition string to determine icon of language is not English; use weather code instead
|
||||||
|
const code = curr.code || -1;
|
||||||
|
if (code > 0) {
|
||||||
|
let w_icon = chooseIconByCode(curr.code);
|
||||||
|
} else {
|
||||||
|
let w_icon = getErr();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
g.setFontAlign(1, 0).setFont("Vector", 90 * this.scale);
|
g.setFontAlign(1, 0).setFont("Vector", 90 * this.scale);
|
||||||
g.drawString(format(hour), this.centerTimeScaleX, this.center.y - 31 * this.scale);
|
g.drawString(format(hour), this.centerTimeScaleX, this.center.y - 31 * this.scale);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue