-
Notifications
You must be signed in to change notification settings - Fork 0
/
his.js
46 lines (38 loc) · 1.11 KB
/
his.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
global.fs = require('fs');
global.jsdom = require("jsdom");
global.jquery = fs.readFileSync("/jquery.js", "utf-8");
String.prototype.Replace = function(a,b){
return this.split(a || ',').join(b || '');
}
var coin = process.argv[2] || 'bitcoin';
jsdom.env({
url: 'https://coinmarketcap.com/currencies/' + coin + '/historical-data/?start=20000101&end=30000101',
src: [jquery],
headers: {
'User-Agent' : 'test'
},
done: function (err, window) {
var $ = window.$;
//console.log($('body').text())
var result = [];
var first = []
$('table tr').each(function( index ) {
var row = [];
$(this).text().split('\n').forEach(function(col,i){
var dat = col.trim();
if(dat !== '' && index !== 0)row.push(row.length === 0 ? new Date(dat) : dat.Replace(',') * 1);
if(dat !== '' && index === 0)row.push(row.length === 0 ? dat : dat.Replace(' '));
});
var obj = {};
row.forEach(function(col,i){
obj[first[i]] = col;
});
if(index === 0){
first = row;
}else{
result.push(obj);
}
});
fs.writeFile('json/' + coin + '.json', JSON.stringify(result),function(){});
}
});