Skip to content
This repository has been archived by the owner on Mar 21, 2023. It is now read-only.

Commit

Permalink
[+] Add end and attempt module
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0is1 committed Nov 27, 2022
1 parent aebf75f commit 0dbab9e
Show file tree
Hide file tree
Showing 7 changed files with 193 additions and 2 deletions.
14 changes: 13 additions & 1 deletion App.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const dexp = require("./src/exportData");
const oneres = require("./src/getOneResult");
const que = require("./src/getQuestions")
const que = require("./src/getQuestions");
const endt = require("./src/endTest");
const anst = require("./src/attemptTest");


console.log("Profanity v1.0.1");
console.log("Author: 0x0is1");
Expand All @@ -14,4 +17,13 @@ switch (parseInt(process.argv[2])) {
break;
case 3:
que.getQuestions(null);
break;
case 4:
endt.endTest(null);
break;
case 5:
anst.getAnswer(null);
break;
default:
console.log("Wrong option selected.")
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"result": "node App.js 2",
"export": "node App.js 1",
"question": "node App.js 3",
"end": "node App.js 4",
"answer": "node App.js 5",
"test": "node tests/test1.js"
},
"repository": {
Expand Down
11 changes: 11 additions & 0 deletions run.bat
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ if exist node_modules\ (
echo 1. Get one result
echo 2. Get all results
echo 3. Get Question Paper
echo 4. End test
echo 5. Get answer

set /p input=Select action:
if %input%==1 (
npm run result
Expand All @@ -22,6 +25,14 @@ if %input%==2 (
if %input%==3 (
npm run question
pause
)
if %input%==4 (
npm run end
pause
)
if %input%==5 (
npm run answer
pause
) else (
echo Wrong option selected
pause
Expand Down
9 changes: 9 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ fi
echo "1. Get one result"
echo "2. Get all results"
echo "3. Get Question Paper"
echo "4. End test"
echo "5. Get Answer"

read -p "Select action: " input
if [ "$input" == "1" ]; then
npm run result
Expand All @@ -19,6 +22,12 @@ elif [ "$input" == "2" ]; then

elif [ "$input" == "3" ]; then
npm run question

elif [ "$input" == "4" ]; then
npm run end

elif [ "$input" == "5" ]; then
npm run answer
else
echo "Wrong option selected"
fi
68 changes: 68 additions & 0 deletions src/attemptTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
const parseOAS = require("./libs/parseOAS");
const prompt = require("prompt-sync")({ sigint: true });

async function getAnswer(rno) {
var answers = {};
if (rno === null) {
var reg_no = prompt('Enter registration number to get answer of: ');
}
else {
var reg_no = rno;
}

await parseOAS.fetch_2attempt(reg_no).then(async data => {
parseOAS.fetch_username(reg_no).then(async un_data => {
console.log(`Name: ${un_data}`);
for (var [i, j] of data.entries()) {
console.log(`[${i + 1}] ${j.TestName}`);
}
if (rno === null) {
var selid = prompt('Select test to get answers: ');
}
else selid = 1;

var set = prompt('Enter set number: ');
var attempt4me = prompt("Attempt this test for you? [y/n]: ")
if (attempt4me != "y") {
reg_no = 12114441; // reg no to attempt, retired ofcourse
}
var tid = data[selid-1].TestId;
var currScore = 0;

// getting current score
await parseOAS.fetch_result(tid, reg_no).then(redata => {
currScore = parseInt(redata[0].MarksObtained);
});

await parseOAS.fetch_qids(tid, set).then(async qiddata => {
for (let [idx, i] of qiddata.entries()) {
await parseOAS.fetch_options(i.QuestionId).then(async opdata => {
var correctOpFound = false;
for (let j of opdata) {
await parseOAS.attemptQuestion(tid, reg_no, set, i.QuestionId, j.OptionId).then(async attemptData => {
await parseOAS.fetch_result(tid, reg_no).then(redata => {
if (parseInt(redata[0].MarksObtained) > currScore) {
currScore = parseInt(redata[0].MarksObtained);
answers[idx] = j.OptionDescription;
correctOpFound = true;
console.log(idx, j.OptionDescription)
}
});
});
if (correctOpFound) break;
}
});
}
await parseOAS.fetch_endTest(tid, reg_no, set).then(async endtdata => {
console.log(endtdata);
console.log(answers);
});
});
});
});

}

module.exports = {
getAnswer
};
36 changes: 36 additions & 0 deletions src/endTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const parseOAS = require("./libs/parseOAS");
const prompt = require("prompt-sync")({ sigint: true });
async function endTest(rno = 12114478) {
if (rno === null) {
var reg_no = prompt('Enter registration number to get marks of: ');
}
else {
var reg_no = rno;
}
await parseOAS.fetch_attempted(reg_no).then(data => {
parseOAS.fetch_username(reg_no).then(async un_data => {
console.log(`Name: ${un_data}`);
for (var [i, j] of data.entries()) {
console.log(`[${i + 1}] ${j.TestName}`);
}
if (rno === null) {
var selid = prompt('Select test to get marks: ');
}
else {
selid = 1;
}
var set = prompt("Enter set number: ");
await parseOAS.fetch_endTest(data[selid-1], reg_no, set).then(async endtdata => {
if (endtdata == "-1") {
console.log("Ended successfully");
return;
}
console.log("Something went wrong.");
});
});
});
}

module.exports = {
endTest
};
55 changes: 54 additions & 1 deletion src/libs/parseOAS.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,56 @@ async function fetch_answers(test_id, login_id = 12114480) {
return resp;
}

async function fetch_testStatus(test_id, login_id = 12114480, set=1) {
var url = `${BASEURL}/CheckForTestSubmitted?LoginId=${login_id}&TestId=${test_id}&Set=${set}`;
var data = await fetch(url, {
"headers": headers(),
"method": "GET"
});
var resp = await data.json();
return resp;
}

async function fetch_endTest(test_id, login_id = 12114480, set=1) {
var url = `${BASEURL}/EndTestDetail`;
var body = {
TestId: test_id,
SetNumber: set,
LoginName: login_id,
TimeRemaining: "15:15",
IsExplicitEnd: "true"
}
var data = await fetch(url, {
"headers": headers(),
"body": JSON.stringify(body),
"method": "POST"
});
var resp = await data.json();
return resp;
}

async function attemptQuestion(test_id, login_id = 12114480, set = 1, question_id, option_id) {
var url = `${BASEURL}/SaveTestResponse`;
var body = {
TestId: test_id,
SetNo: set,
LoginId: login_id,
QuestionId: question_id,
OptionId: option_id,
IsFlagged: "",
IsRightAnswer: 0,
AnswerText: "",
TimeTaken: "13:13"
}
var data = await fetch(url, {
"headers": headers(),
"body": JSON.stringify(body),
"method": "POST"
});
var resp = await data.json();
return resp;
}

module.exports = {
fetch_attempted,
fetch_result,
Expand All @@ -100,5 +150,8 @@ module.exports = {
fetch_options,
fetch_2attempt,
fetch_qids,
fetch_answers
fetch_answers,
fetch_testStatus,
fetch_endTest,
attemptQuestion
};

0 comments on commit 0dbab9e

Please sign in to comment.