-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
68 lines (57 loc) · 1.66 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
var fs = require("fs");
var vttParser=require('./vtt-composer')
/**
* module to parse elex json and convert into srt subtitles-parser data structure (array of segments).
* It could be replaced with another module to convert a different type of json into srt subtitles-parser data structure (array of segments) if not working with Elex.
*/
var elexCrawler= require('./elexToTextCrawlerSegments')
var fileName = process.argv[2];
//TODO: add some validation
// arg 2 needs to exist
// arg 2 needs to be json file
// arg 2 could be csv file?
/**
* Opening file
*/
var data = fs.readFileSync(fileName);
console.log("opened file")
/**
* Parsing json
*/
var dataJson = JSON.parse(data);
console.log("parsed json")
//TODO: add support for CSV?
/**
* convert Elex json into vtt data structure and write to file
*/
// elexCrawler.convert(dataJson,function(resp){
// writeVTTile(resp);
// });
/**
* convert Elex json into text data structure and write to file
*/
elexCrawler.convert(dataJson,function(resp){
writeTextFile(resp);
});
/**
* Write to VTT File
*/
// function writeVTTile(vttDataStructure){
// // var dataSrt = parser.toSrt(vttDataStructure);
// var dataVTT = vttParser.toVtt(vttDataStructure);
// fs.writeFile(fileName+".vtt", dataVTT, "utf8", function(){
// console.log("finished writing vtt file: "+fileName+".vtt");
// })
// }
/**
* Write to plain text file
*/
function writeTextFile(vttDataStructure){
dataTxt="Elections Results ... ";
for(var i =0;i< vttDataStructure.length ; i++){
dataTxt+=vttDataStructure[i].text+" | ";
}
fs.writeFile(fileName+".txt", dataTxt, "utf8", function(){
console.log("finished writing plain file: "+fileName+".txt");
});
}