forked from prasannathapa/makaut-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataExtractor.js
54 lines (54 loc) · 1.94 KB
/
dataExtractor.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
module.exports.getTextArray = (pdf) => {
let textArray = [];
pdf.forEach((val => {
if(val.R && val.R.length > 0){
let str = decodeURIComponent(val.R[0].T);
textArray.push(str);
if(str.startsWith("No Records Found!"))
return {info: "No Records Found"};
}
}))
if(textArray.length <= 2){
return {info:"No Records Found", error:"Result doesnt exist"};
}
let resObj={};
for(let i = 0; i < textArray.length; i++){
if(textArray[i].startsWith("NAME")){
resObj.name = textArray[++i];
}
else if(textArray[i].startsWith("ROLL NO.")){
resObj.roll = textArray[++i];
}
else if(textArray[i].startsWith("REGISTRATION NO")){
resObj.registration = textArray[++i];
}
else if(textArray[i] == 'O' ||
textArray[i] == 'E' ||
textArray[i] == 'A' ||
textArray[i] == 'B' ||
textArray[i] == 'C' ||
textArray[i] == 'D' ||
textArray[i] == 'F' ||
textArray[i] == 'I'){
//resObj.roll = textArray[++i];
let subCode = ""
if(isNaN(textArray[i-3]) && textArray[i-3] != "Points")
subCode = textArray[i-3]
subCode += textArray[i-2]
if(!resObj.result) resObj.result = {};
resObj.result[subCode] = {
"subjectName":textArray[i-1],
"CGPA":textArray[i+1],
"grade":textArray[i],
"weightage":textArray[i+2]
}
i+=2;
}
else if(textArray[i].startsWith("College / Institution")){
resObj.collegeName = textArray[i].substring("College / Institution".length).trim();
}
}
//const fs = require('fs')
//fs.writeFile('result.json', JSON.stringify(pdf), 'utf8', ()=>{console.log("SAVED");});
return resObj;
}