-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_papers.js
50 lines (48 loc) · 1.35 KB
/
get_papers.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
module.exports = {
get_papers : function(entry)
{
var fs = require("fs-extra");
var path = require('path');
var EasyZip = require('easy-zip').EasyZip;
var zip5 = new EasyZip();
function getDirectories(srcpath) {
return fs.readdirSync(srcpath).filter(function(file) {
return fs.statSync(path.join(srcpath, file)).isDirectory();
});
}
var entry = entry.toUpperCase();
var papers_dir = "QuestionPapers/COL";
var output_home_dir = "output";
var output_dir = output_home_dir + "/" + entry;
var json_location ="Data Collection/data_base.json";
var content = fs.readFileSync(json_location);
var data_base = JSON.parse(content);
var courses = data_base[entry]["courses"];
if (!fs.existsSync(output_dir))
{
fs.mkdirSync(output_dir);
}
var dir1 = getDirectories(papers_dir);
no_courses = dir1.length;
for(i = 0; i<no_courses ; i++)
{
if(courses.includes(dir1[i]))
{
fs.copy(papers_dir+"/"+dir1[i], output_dir + "/"+ dir1[i], function (err)
{
if (err)
{
console.error(err);
}
else
{
zip5.zipFolder(output_dir, function()
{
zip5.writeToFile(output_home_dir+"/" +entry+".zip");
});
}
});
}
}
}
};