-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnode_helper.js
48 lines (43 loc) · 1.36 KB
/
node_helper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* Magic Mirror
* Node Helper: MMM-LesJoiesDuCode
*
* By AceLan Kao
* Review by @bugsounet (05/2023)
* MIT Licensed
*/
var NodeHelper = require('node_helper')
const axios = require("axios")
module.exports = NodeHelper.create({
start: function () {
this.data_url = "https://lesjoiesducode.fr/wp-json/wp/v2/posts"
},
getData: function () {
let results = []
axios({ url: this.data_url+"?seed="+Date.now() })
.then(response => {
if (response.data.length) {
response.data.forEach(ljdc => {
let content = {}
content.title = ljdc.title.rendered
content.content = ljdc.content.rendered
results.push(content)
console.log("[LJDC] Fetch:", ljdc.title.rendered)
})
this.sendSocketNotification("DATA_RESULTS", results)
}
})
.catch(error => {
console.error("[LJDC] Fetch data error:", error)
})
},
socketNotificationReceived: function(notification, payload) {
if (notification == "INIT") this.initialize(payload)
},
initialize: function(payload) {
console.log('[LJDC] MMM-LesJoiesDuCode started')
this.config= payload
if (this.config.language == "en") this.data_url = "https://thecodinglove.com/wp-json/wp/v2/posts"
this.getData()
setInterval(() => { this.getData() }, this.config.updateInterval)
}
});