-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
73 lines (67 loc) · 2.05 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
63
64
65
66
67
68
69
70
71
72
73
'use strict';
//warning this may trigger multiple times for one press
//...usually triggers twice based on testing for each press
var conf = require('./conf.js')
var dash_button = require('node-dash-button')
var dash = dash_button("00:bb:3a:a0:e5:ac", null, null, 'all') //address from step above
import Wunderlist from 'wunderlist-api'
const listTitle = conf.params.listTitle
const newItem = conf.params.newItem
const state = conf.params.state
const starred = conf.params.starred
var revision = 0
var listID = 0
const wunderlist = new Wunderlist({
clientId: conf.wunderlist_auth.clientID,
accessToken: conf.wunderlist_auth.accessToken
})
var addItem = () => {
wunderlist.getLists()
.then( response => {
// response
var lists = JSON.parse(response.body)
for(var i=0; i<lists.length; i++){
i == 0 ? console.log('lists found:'+ '\n\t' + lists[i].title)
: console.log('\t' + lists[i].title)
if(lists[i].title == listTitle){
listID = lists[i].id
revision = lists[i].revision
}
}
updateList()
})
.catch( error => {
console.log('ERROR, could not get list!\n' + error)
});
}
var updateList = () => {
if(listID == 0){
console.log('No list with title "' + listTitle +'" found!')
}
else{
console.log('list: "' + listTitle + '" with ID ' + listID + ' found!')
wunderlist.getTasks(listID)
.then( response => {
var item_titles = JSON.parse(response.body).map((item) => item['title'])
console.log(item_titles)
if (item_titles.indexOf(newItem) == -1) {
wunderlist.createTask(listID, newItem, state, starred)
.then( response => {
console.log('list updated')
})
.catch( error => {
console.log('list update failed')
})
} else {
console.log('Item already in list')
}
})
.catch( error => {
console.error(error)
})
}
}
dash.on("detected", function (){
console.log("omg found")
addItem()
});