-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
77 lines (65 loc) · 2.44 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
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
const https = require('https');
const fs = require('fs');
var boardinfo = "";
function iterate(){
const data = fs.readFileSync('file.txt', 'UTF-8');
const lines = data.split(/\r?\n/);
try {
lines.forEach((line) => {
https.get({
hostname: 'trello.com',
path: `/b/`+line+`.json`,
headers: {'User-Agent': `${Math.random().toString(16).substring(2,16)}`}
}, (r) => {
var data = "";
r.on('data', (d) => {
data+=d;
})
r.on('close', () => {
boardinfo = JSON.parse(data);
});
})
var actions = [];
(function untilDeath(beforeval) {
https.get({
hostname: 'api.trello.com',
path: `/1/boards/`+line+`/actions?limit=1000${beforeval ? `&before=${beforeval}` : ``}`,
headers: {'User-Agent': `${Math.random().toString(16).substring(2,16)}`}
}, (r) => {
var cmpdta = "";
r.on('data', (d) => {
cmpdta+=d;
})
r.on('close', () => {
cmpdta = JSON.parse(cmpdta);
console.log('date %s, size %d', beforeval, cmpdta.length);
console.log(cmpdta.length)
if(cmpdta.length < 1000) {
if(cmpdta.length) actions.push(cmpdta);
return makeFile({}, [].concat.apply([], actions));
} else
var lastKey = Object.keys(cmpdta).sort().reverse()[0];
//console.log(cmpdta[lastKey])
untilDeath(cmpdta[lastKey]["date"]);
cmpdta.pop();
actions.push(cmpdta);
});
r.on('error', () => {
throw new Error('-----HTTPS Error Occurred, Please retry :(');
});
});
})();
});
} catch (error) {
return true;
}
}
function makeFile(trelloBoard, actions) {
trelloBoard["actions"] = actions;
let vari = trelloBoard["actions"][0]["id"];
fs.createWriteStream(vari+'.json');
fs.writeFile(`${vari}.json`, JSON.stringify(trelloBoard, null, `\t`), (c) => {
if(c) console.log(c);
});
}
iterate()