-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
52 lines (46 loc) · 1.36 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
const winston = require('winston');
require('dotenv').config();
const extractor = require('./extractor');
const transformer = require('./transformer');
const loader = require('./loader');
const logger = winston.createLogger({
transports: [new winston.transports.Console()],
format: winston.format.combine(
winston.format.timestamp(),
winston.format.json(),
),
});
const getConfig = () => {
const requiredEnv = [
'SABADELL_USER_ID',
'SABADELL_PIN',
'YNAB_ACCESS_TOKEN',
'YNAB_ACCOUNT_ID',
'YNAB_BUDGET_ID',
];
requiredEnv.forEach((key) => {
if (!process.env[key]) {
throw new Error(`Required configuration ${key} is missing`);
}
});
return {
sabadell: {
userId: process.env.SABADELL_USER_ID,
pin: process.env.SABADELL_PIN,
},
ynab: {
accessToken: process.env.YNAB_ACCESS_TOKEN,
accountId: process.env.YNAB_ACCOUNT_ID,
budgetId: process.env.YNAB_BUDGET_ID,
},
};
};
async function main() {
const config = getConfig();
// const sabadellTransactions = await extractor.transactionsFromSite(config.sabadell, logger);
const sabadellTransactions = await extractor.transactionsFromFile('transactions.txt', logger);
const ynabTransactions = transformer.transform(sabadellTransactions, logger);
await loader.load(ynabTransactions, config.ynab, logger);
logger.info('Done');
}
main();