-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (33 loc) · 1.04 KB
/
index.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
require('dotenv').config();
var request = require('request');
var dash_button = require('node-dash-button');
var request = require('request');
var dash = dash_button([process.env.BAD_BUTTON, process.env.GOOD_BUTTON], null, null, 'all'); //address from step above
var postPoint = function(metric) {
var bothanURL = process.env.BOTHAN_URL
var metricURL = bothanURL + '/metrics/' + metric + '.json'
var date = new Date()
request(metricURL, function(error, response, body) {
json = JSON.parse(body)
value = (json == null) ? 0 : json.value
request.post(metricURL, {
auth: {
user: process.env.BOTHAN_USERNAME,
pass: process.env.BOTHAN_PASSWORD
},
json: {
time: date.toISOString(),
value: value + 1
}
})
})
}
dash.on("detected", function (dash_id){
if (dash_id === process.env.BAD_BUTTON){
console.log("Naughty!")
postPoint('home-behaviour-points')
} else if (dash_id === process.env.GOOD_BUTTON){
console.log("Good!");
postPoint('home-acheivement-points')
}
});