diff --git a/MMM-Jast.js b/MMM-Jast.js index ad1143c..7eb7bad 100644 --- a/MMM-Jast.js +++ b/MMM-Jast.js @@ -1,6 +1,6 @@ /*! ***************************************************************************** mmm-jast - Version 2.6.0 + Version 2.6.2 A minimalistic stock ticker based on Yahoo's finance API for the MagicMirror² platform. Please submit bugs at https://github.com/jalibu/MMM-Jast/issues diff --git a/node_helper.js b/node_helper.js index 36e885a..ae06629 100644 --- a/node_helper.js +++ b/node_helper.js @@ -1,6 +1,6 @@ /*! ***************************************************************************** mmm-jast - Version 2.6.0 + Version 2.6.2 A minimalistic stock ticker based on Yahoo's finance API for the MagicMirror² platform. Please submit bugs at https://github.com/jalibu/MMM-Jast/issues @@ -11,7 +11,7 @@ This file is auto-generated. Do not edit. ***************************************************************************** */ -"use strict";var e=require("node_helper"),t=require("logger"),r=require("yahoo-finance2");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function n(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var o=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,o.get?o:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var s=n(e),i=n(t),a=o(r); +"use strict";var e=require("node_helper"),t=require("logger"),r=require("yahoo-finance2");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function n(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var o=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,o.get?o:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var s=n(e),i=n(t),c=o(r); /*! ***************************************************************************** Copyright (c) Microsoft Corporation. @@ -26,4 +26,4 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ -function c(e,t,r,o){return new(r||(r=Promise))((function(n,s){function i(e){try{c(o.next(e))}catch(e){s(e)}}function a(e){try{c(o.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,a)}c((o=o.apply(e,t||[])).next())}))}const u=["regularMarketChange","regularMarketChangePercent","regularMarketPrice","currency","longName","regularMarketPreviousClose"];module.exports=s.create({start(){i.log(`${this.name} helper method started...`)},socketNotificationReceived(e,t){return c(this,void 0,void 0,(function*(){if("JAST_STOCKS_REQUEST"===e){let e=yield class{static requestStocks(e){return c(this,void 0,void 0,(function*(){const t=[],r=[];for(const t of e.stocks)r.push(a.default.quoteSummary(t.symbol,{modules:["price"]}));const o=yield Promise.all(r.map((e=>e.catch((e=>e)))));for(const[r,n]of o.entries())if(n instanceof Error)i.warn(`API request for ${e.stocks[r].symbol} failed:`,n.message);else if(n.price){const o={symbol:e.stocks[r].symbol,name:e.stocks[r].name,quantity:e.stocks[r].quantity};t.push({price:n.price,meta:o})}else i.warn(`Response for ${e.stocks[r].symbol} does not satisfy expected payload.`);return t}))}}.requestStocks(t);e=e.filter((e=>u.every((t=>!!Object.prototype.hasOwnProperty.call(e.price,t)||(i.warn(`Skipped symbol '${e.meta.symbol}' as it's response did not have required property '${t}'. This is usually the case when a symbol is misspelled`),!1)))));const r={lastUpdate:Date.now(),stocks:e};this.sendSocketNotification("JAST_STOCKS_RESPONSE",r)}else i.warn(`${e} is invalid notification`)}))}}); +function a(e,t,r,o){return new(r||(r=Promise))((function(n,s){function i(e){try{a(o.next(e))}catch(e){s(e)}}function c(e){try{a(o.throw(e))}catch(e){s(e)}}function a(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,c)}a((o=o.apply(e,t||[])).next())}))}const u=["regularMarketChange","regularMarketChangePercent","regularMarketPrice","currency","longName","regularMarketPreviousClose"];module.exports=s.create({start(){i.log(`${this.name} helper method started...`)},socketNotificationReceived(e,t){return a(this,void 0,void 0,(function*(){if("JAST_STOCKS_REQUEST"===e){let e=yield class{static requestStocks(e){return a(this,void 0,void 0,(function*(){const t=[],r=[];for(const t of e.stocks)r.push(c.default.quoteSummary(t.symbol,{modules:["price"]}));const o=yield Promise.all(r.map((e=>e.catch((e=>e)))));for(const[r,n]of o.entries())if(n instanceof Error)i.warn(`API request for ${e.stocks[r].symbol} failed:`,n.message);else if(n.price){const o={symbol:e.stocks[r].symbol,name:e.stocks[r].name,quantity:e.stocks[r].quantity};"GBp"===n.price.currency&&(n.price.regularMarketPrice/=100,n.price.regularMarketChange/=100,n.price.currency="GBP"),t.push({price:n.price,meta:o})}else i.warn(`Response for ${e.stocks[r].symbol} does not satisfy expected payload.`);return t}))}}.requestStocks(t);e=e.filter((e=>u.every((t=>!!Object.prototype.hasOwnProperty.call(e.price,t)||(i.warn(`Skipped symbol '${e.meta.symbol}' as it's response did not have required property '${t}'. This is usually the case when a symbol is misspelled`),!1)))));const r={lastUpdate:Date.now(),stocks:e};this.sendSocketNotification("JAST_STOCKS_RESPONSE",r)}else i.warn(`${e} is invalid notification`)}))}}); diff --git a/package-lock.json b/package-lock.json index d69c879..a8a2dc9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "mmm-jast", - "version": "2.6.1", + "version": "2.6.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "mmm-jast", - "version": "2.6.1", + "version": "2.6.2", "license": "MIT", "dependencies": { "yahoo-finance2": "^1.14.4" @@ -2125,10 +2125,22 @@ "license": "MIT" }, "node_modules/node-fetch": { - "version": "2.6.1", - "license": "MIT", + "version": "2.6.7", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", + "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", + "dependencies": { + "whatwg-url": "^5.0.0" + }, "engines": { "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } } }, "node_modules/normalize-package-data": { @@ -2987,6 +2999,11 @@ "node": ">=8.0" } }, + "node_modules/tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=" + }, "node_modules/tsconfig-paths": { "version": "3.11.0", "dev": true, @@ -3093,6 +3110,20 @@ "spdx-expression-parse": "^3.0.0" } }, + "node_modules/webidl-conversions": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", + "integrity": "sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE=" + }, + "node_modules/whatwg-url": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha1-lmRU6HZUYuN2RNNib2dCzotwll0=", + "dependencies": { + "tr46": "~0.0.3", + "webidl-conversions": "^3.0.0" + } + }, "node_modules/which": { "version": "2.0.2", "dev": true, @@ -4521,7 +4552,12 @@ "dev": true }, "node-fetch": { - "version": "2.6.1" + "version": "2.6.7", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", + "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", + "requires": { + "whatwg-url": "^5.0.0" + } }, "normalize-package-data": { "version": "2.5.0", @@ -5046,6 +5082,11 @@ "is-number": "^7.0.0" } }, + "tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=" + }, "tsconfig-paths": { "version": "3.11.0", "dev": true, @@ -5119,6 +5160,20 @@ "spdx-expression-parse": "^3.0.0" } }, + "webidl-conversions": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", + "integrity": "sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE=" + }, + "whatwg-url": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha1-lmRU6HZUYuN2RNNib2dCzotwll0=", + "requires": { + "tr46": "~0.0.3", + "webidl-conversions": "^3.0.0" + } + }, "which": { "version": "2.0.2", "dev": true, diff --git a/package.json b/package.json index c37edc7..096f85a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mmm-jast", - "version": "2.6.1", + "version": "2.6.2", "description": "A minimalistic stock ticker based on Yahoo's finance API for the MagicMirror² platform.", "main": "MMM-Jast.js", "repository": { diff --git a/src/backend/JastBackendUtils.ts b/src/backend/JastBackendUtils.ts index cf73809..da9fd01 100644 --- a/src/backend/JastBackendUtils.ts +++ b/src/backend/JastBackendUtils.ts @@ -24,6 +24,12 @@ export default class JastBackendUtils { name: config.stocks[index].name, quantity: config.stocks[index].quantity } + // Manually convert GBp to GBP + if (response.price.currency === 'GBp') { + response.price.regularMarketPrice /= 100 + response.price.regularMarketChange /= 100 + response.price.currency = 'GBP' + } stocks.push({ price: response.price, meta }) } else { Log.warn(`Response for ${config.stocks[index].symbol} does not satisfy expected payload.`)