Skip to content

Instantly share code, notes, and snippets.

@abhishekwebcode
Created May 12, 2019 17:22
Show Gist options
  • Save abhishekwebcode/896bd7a7989aea13dc41be39f644d6bd to your computer and use it in GitHub Desktop.
Save abhishekwebcode/896bd7a7989aea13dc41be39f644d6bd to your computer and use it in GitHub Desktop.
program to generate mongo json of questions for meyers test
const fs = require(`fs`);
var path = require('path');
var updater = ( path.resolve( __dirname, "./raw.txt" ) );
var updater2 = ( path.resolve( __dirname, "./done.json" ) );
raw=fs.readFileSync(updater);
setInterval(()=>{},999999999);
const list = raw.toString().split(`\n`);
const obj={
"title": "Choose the option that describes you best",
"answers": [
{
"option": "Introvert",
"value": "I",
"image_url": "https://sample-videos.com/img/Sample-jpg-image-50kb.jpg"
},
{
"option": "Maybe",
"value": "N",
"image_url": "https://sample-videos.com/img/Sample-jpg-image-50kb.jpg"
}
]
};
const mainList=[];
const list1 = {
E:[1,5,9,13,17],
S:[2,6,10,14,18],
T:[3,7,11,15,19],
J:[4,8,12,16,20]
}
const list2 = {
I:[1,5,9,13,17],
N:[2,6,10,14,18],
F:[3,7,11,15,19],
P:[4,8,12,16,20]
}
function getType(listItem,qno) {
for (t in listItem) {
if (listItem[t].indexOf(qno)!=-1) {
return t
}
}
}
for (let i = 0; i < list.length; i=i+2) {
first=(list[i].slice(3)).replace(`“\u0018`,"").replace(`/\\r?\\n|\\r/g`,"");
second=(list[i+1].slice(3)).replace(`“\u0018`,"").replace(`/\\r?\\n|\\r/g`,"");
qno=(i/2+1);
let uu=Object.create(obj);
uu.answers=[{
"option": first,
"value": getType(list1,qno),
"image_url": "https://sample-videos.com/img/Sample-jpg-image-50kb.jpg"
},
{
"option": second,
"value": getType(list2,qno),
"image_url": "https://sample-videos.com/img/Sample-jpg-image-50kb.jpg"
}
];
uu["title"]= "Choose the option that describes you best";
mainList.push(uu);
}
fs.writeFileSync(updater2,JSON.stringify(mainList));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment