schat2-clive/assets/curate-jeopardy.js

37 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

2021-11-06 00:33:52 +00:00
'use strict';
const fs = require('fs').promises;
const linkify = require('linkify-it')();
2021-11-06 00:33:52 +00:00
const questions = require('./jeopardy_raw.json');
async function init() {
const curatedQuestions = await Promise.all(questions.map(async (question) => {
const links = linkify.match(question.question);
if (links?.length > 0 || /\[jpe?g\]|seen here/i.test(question.question)) {
return null;
}
2021-11-06 00:33:52 +00:00
return {
...question,
question: question.question.replace(/^'|'$/g, ''),
2021-11-14 23:08:40 +00:00
answer: question.answer
.replace(/"|\\/g, '') // strip off quotes and backslashes first, to make sure they don't get in the way of stripping off articles from the beginning of a string
.replace(/^(the|an|a)\b(?!-)\s*|\(.*?\)\s*/gi, '')
2021-11-14 23:08:40 +00:00
.trim(),
fullAnswer: question.answer.replace(/\\/g, ''),
value: Number('$3,800'.match(/\d+/g).join('')),
};
}));
2021-11-06 00:33:52 +00:00
const filteredQuestions = curatedQuestions.filter(Boolean);
await fs.writeFile('assets/jeopardy.json', JSON.stringify(filteredQuestions, null, 4));
console.log(curatedQuestions);
console.log(`Saved ${filteredQuestions.length} questions, discarded ${questions.length - filteredQuestions.length}`);
2021-11-06 00:33:52 +00:00
}
init();