-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
62 lines (57 loc) · 1.58 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
var PythonShell = require('python-shell')
var request = require('request')
var conversions = 0
setInterval(function() {
request.get('https://staging-api.opteo.com/render/gongcount', { timeout: 1500 }, function(
err,
bod1,
count
) {
if (err) {
console.log(err)
} else {
var new_conversions = +count
console.log('conversions: ', new_conversions)
if(new_conversions > conversions) {
conversions = new_conversions
console.log('new conversion found!')
console.log('running python')
PythonShell.run('led.py', {scriptPath: '/home/pi/conversion-gong'}, function(err) {
if(err) {
console.log(err)
} else {
console.log('finished script')
}
})
}
}
})
}, 5000)
// setInterval(function() {
// report.getReport('v201609', {
// reportName: 'Opteo',
// reportType: 'ACCOUNT_PERFORMANCE_REPORT',
// fields: ['AllConversions'],
// format: 'CSV',
// startDate: new Date("01/01/2010"),
// endDate: new Date("01/01/2018")
// }, function(err, report) {
// if(err) {
// console.log(err)
// } else {
// var new_conversions = +report.split('\n')[2].split(',').join('').split("\"").join('')
// console.log('conversions: ', new_conversions)
// if(new_conversions > conversions) {
// conversions = new_conversions
// console.log('new conversion found!')
// console.log('running python')
// PythonShell.run('led.py', function(err) {
// if(err) {
// console.log(err)
// }
// console.log('finished script')
// })
// }
// }
// })
// }, 5000)