-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
111 lines (77 loc) · 3.45 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
const express = require('express');
const app = express();
const port = 3000;
const extractor = require('./extractor');
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
const jsonfile = require('jsonfile')
app.use(express.static('public'));
const questions = [
"hi1",
"hi2",
"hi3"
]
app.get('/question', (req, res) => {
var question = questions[Math.floor(Math.random()*questions.length)];
res.send(question);
});
app.get('/response', (req, res) => {
//const responsedd = req.query.reponse;
var data = " {\n \"documents\": [\n {\n \"language\": \"en\",\n \"id\": \"0\",\n \"text\": \""+req.query.response+"\"\n }\n ]\n }";
//console.log(data)
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === this.DONE) {
//console.log(this.responseText);
}
});
xhr.open("POST", "https://eastus.api.cognitive.microsoft.com/text/analytics/v2.0/keyPhrases", false);
xhr.setRequestHeader("ocp-apim-subscription-key", "8bd00edfaa1e4b628dc659978083bbd9");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("Accept", "application/json");
xhr.send(data);
//console.log("hi")
//const phrases = JSON.parse(xhr.responseText)["documents"]["0"].keyPhrases;
const phrases = ["Python", "C"]
var userQuestions = JSON.parse('{"Questions":{"Technical":[], "General":[]}}');
jsonfile.readFile('./Questions.json')
.then(read => {
// console.log(read);
var questions = read;
for (var i = 0; i < questions["Questions"]["Technical"].length; i++) {
userQuestions["Questions"]["Technical"].push(questions["Questions"]["Technical"][i]);
}
var q1 = Math.round(Math.random() * 76);
var q2 = q1;
var q3 = q1;
while (q2 == q1) {
q2 = Math.round(Math.random() * 76);
}
while (q3 == q1 || q3 == q2) {
q3 = Math.round(Math.random() * 76);
}
console.log(q1)
userQuestions["Questions"]["General"].push(questions["Questions"]["General"][q1]);
userQuestions["Questions"]["General"].push(questions["Questions"]["General"][q2]);
userQuestions["Questions"]["General"].push(questions["Questions"]["General"][q3]);
//console.log(myLangs);
res.send(userQuestions);
//res.send(userQuestions); //Sends education & projects related stuff
})
.catch(error => console.error(error))
// res.send(score);
});
app.get('/', (req, res) => {
//res.sendFile(__dirname + '/index.html');
try{
extractor.fileToJSON('resume.pdf').then((result) => {
//res.send(result["experience"]);
res.redirect('/response?response='+result["experience"])
}).catch(error => new function(){
console.log("Error Status: " + error);
})
}catch( e){
console.log("Fixme: " + e.toString());
}
});
app.listen(port, () => console.log(`Example app listening on port ${port}!`));