-
Notifications
You must be signed in to change notification settings - Fork 0
/
discus_fish_page.js
64 lines (56 loc) · 2.27 KB
/
discus_fish_page.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
var fs = require('fs');
var utils = require('./utils');
var transactions = [], offset = +process.argv[2] || 0;
function addPage($, callback) {
var $transactions = utils.getPageElements($);
grubTransactionPageNext($, $transactions, 0, callback);
}
function grubTransactionPageNext($, $transactions, transactionPageIndex, callback) {
var transaction = $transactions[transactionPageIndex];
if( transaction ) {
var $txDiv = $(transaction);
var $table = $txDiv.find('table').first();
var $trs = $table.find('tr');
var isBaseCoin = $($trs[1]).find('td').first().children().length == 1;
if( isBaseCoin ) {
var elementUrl = utils.blockchainUrl + $($trs[0]).find('a')[0].pathname + '?show_adv=true';
utils.sendRequest(elementUrl, function ($$) {
addTransactionPage($$);
grubTransactionPageNext($, $transactions, transactionPageIndex + 1, callback);
});
} else
grubTransactionPageNext($, $transactions, transactionPageIndex + 1, callback);
} else
callback();
}
function addTransactionPage($) {
var $main = $('.row-fluid').first();
var $mainDivs = $main.children();
var $div1 = $($mainDivs[0]);
var $dateTr = $($div1.find('.table').find('tr')[2]);
var date = $dateTr.find('td').last().text().trim();
var $blockNTr = $($div1.find('.table').find('tr')[3]);
var blockN = $blockNTr.find('td').last().text().trim();
var $div3 = $($mainDivs[2]);
var coinBaseText = $div3.text();
var user = coinBaseText.split('Mined by ')[1];
transactions.push({
blockN: blockN,
date: date,
coinBaseText: coinBaseText,
user: user ? user.trim() : ''
});
}
utils.sendRequest(utils.discusFishUrl + '?offset=' + offset, function ($) {
addPage($, function() {
console.log('Transactions length: ' + transactions.length);
var fileName = 'pages/discus_fish_time_' + (new Date).getTime() + '_offset_' + offset + '.json';
var fileContent = JSON.stringify(transactions, null, 4);
fs.writeFile(fileName, fileContent, function(err) {
if( err )
console.log(err);
else
console.log('The file was saved: ' + fileName);
});
});
});