{"size": 1426, "ext": "js", "max_stars_repo_path": "parser/result-parser.js", "max_stars_repo_name": "ipranshulsingla/ggsipuresults", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "parser/result-parser.js", "max_issues_repo_name": "ipranshulsingla/ggsipuresults", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "parser/result-parser.js", "max_forks_repo_name": "ipranshulsingla/ggsipuresults", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 41.9411764706, "max_line_length": 166, "alphanum_fraction": 0.6451612903}
var fs=require('fs'),
child_process = require('child_process'),
path=require('path'),
os=require('os'),
subjectParser=require('./subject-parser'),
studentParser=require('./student-parser');

module.exports=(fileName,pdfToTxt=false)=>{
    var obj={};
    var basepath=path.dirname(__dirname);
    var pdfPath=path.join(basepath+path.sep+'Resources'+path.sep+'PDFResults'+path.sep+fileName);
    var txtPath=path.join(basepath+path.sep+'Resources'+path.sep+'FinalResults'+path.sep+path.basename(fileName,'.pdf')+'.txt');
    if(pdfToTxt){
        try{
            if(os.platform=='linux')
                child_process.execSync(`pdftotext -raw ${pdfPath} ${txtPath}`);
            else
                child_process.execSync(`cd /d ${path.dirname(pdfPath)}`+'&'+`pdftotext -raw ${fileName} ${'../FinalResults/'+path.basename(fileName,'.pdf')+'.txt'}`);
            console.log('New File Added',fileName);
        }
        catch(err){
            console.log('Server Crashed\nConversion Failed PDF to TEXT\n');
            process.exit();
        }
    }
    var result=fs.readFileSync(txtPath,'utf8');
    var subjectsRegex=/S\.No\. Paper([^]*?)\f/g;
    var subjectsArray=result.match(subjectsRegex);
    obj.subjects=subjectParser(subjectsArray);
    var studentsRegex=/Result of Programme Code:([^]*?)\f/g;
    var studentsArray=result.match(studentsRegex);
    obj.students=studentParser(studentsArray);
    return obj;
};