-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwriteHistory.js
25 lines (20 loc) · 962 Bytes
/
writeHistory.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
const fs = require('fs')
const dateNow = Date.now()
getCurrentBalances()
async function getCurrentBalances() {
try {
const jsonStripe = await fs.readFileSync('docs/stripe.json', 'utf8')
const jsonBank = await fs.readFileSync('docs/bank.json', 'utf8')
const jsonDebt = await fs.readFileSync('docs/debt.json', 'utf8')
const dataStripe = JSON.parse(jsonStripe).available[0].amount / 100
const dataBank = JSON.parse(jsonBank).balances.account
const dataDebt = JSON.parse(jsonDebt).debt
await writeData(dataBank, dataStripe, dataDebt)
} catch (error) { return error }
}
async function writeData(dataBank, dataStripe, dataDebt) {
const historyJSON = await fs.readFileSync('docs/history.json', 'utf8')
let history = JSON.parse(historyJSON)
history[dateNow] = { stripe: dataStripe, bank: dataBank, debt: dataDebt }
await fs.writeFileSync('docs/history.json', JSON.stringify(history))
}