-
Notifications
You must be signed in to change notification settings - Fork 8
/
CanvasDataDL_Tables_Latest.cdconfig
62 lines (52 loc) · 1.58 KB
/
CanvasDataDL_Tables_Latest.cdconfig
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
var fs = require('fs');
var async = require('async');
var https = require('https');
var request = require('request');
var CanvasDataAPICall = require('./CanvasDataAuth_Tables.js');
var dir = "IRCDDLDIRREPLACEME";
var q = async.queue(function(task, cb) {
var dl = fs.createWriteStream(dir + '/' + task.target)
request
.get(task.url)
.on('response', function(response) {
var conlenmb = response.headers['content-length'] / 1024 / 1024;
var size = conlenmb | 0;
console.log(task.target + ', Response: ' + response.statusCode + ', Size in MB: ' + size + ', Type: ' + response.headers['content-type']);
})
.on('error', function(err) {
console.log(err);
cb(err);
})
.pipe(dl);
dl.on('finish', function(){
cb();
});
}, 20);
q.drain = function() {
console.log('Done.')
};
CanvasDataAPICall('', function(result) {
if (!fs.existsSync(dir)){
fs.mkdirSync(dir);
}
res=result
//console.log(res);
abt=res.artifactsByTable
//console.log(tables);
for (var tables in abt) {
if (abt.hasOwnProperty(tables)) {
var tableObj = abt[tables];
console.log(tableObj);
tableObj.files.forEach(function(file) {
var url = file.url;
var filename = file.filename;
file.target = filename;
q.push(file, function(err) {
if (err) {
console.log(err);
}
});
});
}
}
});