-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
75 lines (59 loc) · 1.38 KB
/
test.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
74
75
const low = require('lowdb')
const FileSync = require('lowdb/adapters/FileSync')
const moment = require('moment')
const CREDS = require('./creds');
const Push = require( 'pushover-notifications' )
const adapter = new FileSync('db.json')
const db = low(adapter)
const today = moment().format('DD MMM YYYY');
const date = '26 Apr 2018'
const amount = '3.72'
const count = db
.get('transactions')
.size()
.value()
const transactions = db
.get('transactions')
.value()
const transaction = db
.get('transactions')
.last()
.value()
const todaysTotal = db
.get('transactions')
.filter({ date: today })
.value()
if (transaction.date === date && transaction.amount === amount) {
// do nothing
}
else {
// add transaction
db.get('transactions')
.push({ id: count +1, date: date, amount: amount})
.write()
db.update('count', n => n + 1)
.write()
console.log('New Tranaction: ' + amount)
var total = 0;
for(var i in todaysTotal) {
total += parseFloat(todaysTotal[i].amount);
}
console.log('Spent Today: ' + total)
var p = new Push( {
user: CREDS.pushover_user,
token: CREDS.pushover_token,
})
var msg = {
message: 'Amount: $' + amount + ' (Today: $' + total + ')', // required
title: "New Transaction",
sound: 'magic',
device: CREDS.pushover_device,
priority: 1
}
p.send( msg, function( err, result ) {
if ( err ) {
throw err
}
console.log( result )
})
}