-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathnode_helper.js
More file actions
37 lines (32 loc) · 1.3 KB
/
node_helper.js
File metadata and controls
37 lines (32 loc) · 1.3 KB
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
const request = require('request');
const moment = require('moment');
const NodeHelper = require("node_helper");
module.exports = NodeHelper.create({
start: function() {
console.log("Starting node helper for: " + this.name);
},
socketNotificationReceived: function(notification, payload) {
if(notification === 'CONFIG'){
this.config = payload;
var efa_url = this.config.efaUrl;
efa_url += '&name_dm=' + this.config.stopID;
efa_url += '&type_dm=any';
efa_url += '&line=' + this.config.lines.join('&line=');
efa_url += '&outputFormat=json';
efa_url += '&limit=' + this.config.maxDepartures;
efa_url += '&itdTime=' + moment().format('HHmm');
efa_url += '&itdDate=' + moment().format('YYYYMMDD');
console.log(efa_url);
this.getData(efa_url, this.config.stopID);
}
},
getData: function(options, stopID) {
request(options, (error, response, body) => {
if (response.statusCode === 200) {
this.sendSocketNotification("TRAMS" + stopID, JSON.parse(body));
} else {
console.log("Error getting tram connections " + response.statusCode);
}
});
}
});