forked from symdesign/mintos-trading-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog-overview.js
More file actions
99 lines (77 loc) · 5.22 KB
/
log-overview.js
File metadata and controls
99 lines (77 loc) · 5.22 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
const init = require('./init');
const createCsvWriter = require('csv-writer').createObjectCsvWriter;
async function log_nar( page ) {
await page.goto('https://www.mintos.com/en/overview/')
const csvWriter = createCsvWriter({
path: 'overview.csv',
header: [
{id: 'date', title: 'Date (dd.mm.yyyy)'},
{id: 'availableFunds', title: 'Available Funds (EUR)'},
{id: 'investedFunds', title: 'Invested Funds (EUR)'},
{id: 'totalBallance', title: 'Total Balance (EUR)'},
{id: 'nar', title: 'Net Annual Return (%)'},
{id: 'interest', title: 'Interest (EUR)'},
{id: 'latePaymentFees', title: 'Late Payment Fees (EUR)'},
{id: 'badDebt', title: 'Bad Debt (EUR)'},
{id: 'premiums', title: 'Premiums (EUR)'},
{id: 'serviceFees', title: 'Service Fees (EUR)'},
{id: 'campaignRewards', title: 'Campaign Rewards (EUR)'},
{id: 'totalProfit', title: 'Total Profit (EUR)'},
{id: 'numberOfInvestments', title: 'Number of Investments'},
{id: 'current', title: 'Current'},
{id: 'gracePeriod', title: 'Grace Period'},
{id: 'daysLate_1_15', title: '1-15 Days late'},
{id: 'daysLate_16_30', title: '16-30 Days late'},
{id: 'daysLate_31_60', title: '31-60 Days late'},
{id: 'daysLate_60_up', title: '60+ Days late'},
{id: 'defaulted', title: 'Default'},
],
append: true,
fieldDelimiter: ';'
});
const data = await page.evaluate( () => {
let today = new Date();
let dd = String(today.getDate()).padStart(2, '0');
let mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
let yyyy = today.getFullYear();
let euro = /€\s((\d+\s)?\d+\.\d{2})/
let percentage = /((\d+\s)?\d+\.\d{2})%/
let firstBox = document.querySelector('#mintos-boxes .overview-box:nth-child(1)');
let secondBox = document.querySelector('#mintos-boxes .overview-box:nth-child(2)');
let thirdBox = document.querySelector('#mintos-boxes .overview-box:nth-child(3)');
return {
date: dd + '.' + mm + '.' + yyyy,
availableFunds: firstBox.querySelector('.data tr:nth-child(1) td:last-child').innerText.replace( euro, '$1').replace(' ',''),
investedFunds: firstBox.querySelector('.data tr:nth-child(2) td:last-child').innerText.replace( euro, '$1').replace(' ',''),
totalBallance: firstBox.querySelector('.data tr:nth-child(3) td:last-child').innerText.replace( euro, '$1').replace(' ',''),
nar: secondBox.querySelector('.header .value').innerText.replace( percentage, '$1'),
interest: secondBox.querySelector('.data tr:nth-child(1) td:last-child').innerText.replace( euro, '$1').replace(' ',''),
latePaymentFees: secondBox.querySelector('.data tr:nth-child(2) td:last-child').innerText.replace( euro, '$1').replace(' ',''),
badDebt: secondBox.querySelector('.data tr:nth-child(3) td:last-child').innerText.replace( euro, '$1').replace(' ',''),
premiums: secondBox.querySelector('.data tr:nth-child(4) td:last-child').innerText.replace( euro, '$1').replace(' ',''),
serviceFees: secondBox.querySelector('.data tr:nth-child(5) td:last-child').innerText.replace( euro, '$1').replace(' ',''),
campaignRewards: secondBox.querySelector('.data tr:nth-child(6) td:last-child').innerText.replace( euro, '$1').replace('\n','').replace('+ Earn more',''),
totalProfit: secondBox.querySelector('.data tr:nth-child(7) td:last-child').innerText.replace( euro, '$1').replace(' ',''),
numberOfInvestments: thirdBox.querySelector('.header .value').innerText,
current: thirdBox.querySelector('.data tr:nth-child(1) td:last-child').innerText.replace( euro, '$1').replace(' ',''),
gracePeriod: thirdBox.querySelector('.data tr:nth-child(2) td:last-child').innerText.replace( euro, '$1').replace(' ',''),
daysLate_1_15: thirdBox.querySelector('.data tr:nth-child(3) td:last-child').innerText.replace( euro, '$1').replace(' ',''),
daysLate_16_30: thirdBox.querySelector('.data tr:nth-child(4) td:last-child').innerText.replace( euro, '$1').replace(' ',''),
daysLate_31_60: thirdBox.querySelector('.data tr:nth-child(5) td:last-child').innerText.replace( euro, '$1').replace(' ',''),
daysLate_60_up: thirdBox.querySelector('.data tr:nth-child(6) td:last-child').innerText.replace( euro, '$1').replace(' ',''),
defaulted: thirdBox.querySelector('.data tr:nth-child(7) td:last-child').innerText.replace( euro, '$1').replace(' ',''),
}
});
csvWriter.writeRecords([data]);
}
// If js file called directly
if (require.main === module) {
(async () => {
const i = await init();
const page = i.page;
const browser = i.browser;
await log_nar( page );
await browser.close();
})()
}
module.exports = log_nar;