2021-11-06 00:33:52 +00:00
'use strict' ;
const fs = require ( 'fs' ) . promises ;
2021-11-14 18:55:14 +00:00
const linkify = require ( 'linkify-it' ) ( ) ;
2021-11-06 00:33:52 +00:00
const questions = require ( './jeopardy_raw.json' ) ;
async function init ( ) {
2021-11-14 18:55:14 +00:00
const curatedQuestions = await Promise . all ( questions . map ( async ( question ) => {
const links = linkify . match ( question . question ) ;
2021-11-14 23:38:50 +00:00
if ( links ? . length > 0 || /\[jpe?g\]|seen here/i . test ( question . question ) ) {
2021-11-14 18:55:14 +00:00
return null ;
}
2021-11-06 00:33:52 +00:00
2021-11-14 18:55:14 +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
2021-11-15 14:51:10 +00:00
. replace ( /^(the|an|a)\b(?!-)\s*|\(.*?\)\s*/gi , '' )
2021-11-14 23:08:40 +00:00
. trim ( ) ,
fullAnswer : question . answer . replace ( /\\/g , '' ) ,
2021-11-15 14:51:10 +00:00
value : Number ( '$3,800' . match ( /\d+/g ) . join ( '' ) ) ,
2021-11-14 18:55:14 +00:00
} ;
} ) ) ;
2021-11-06 00:33:52 +00:00
2021-11-14 23:38:50 +00:00
const filteredQuestions = curatedQuestions . filter ( Boolean ) ;
await fs . writeFile ( 'assets/jeopardy.json' , JSON . stringify ( filteredQuestions , null , 4 ) ) ;
2021-11-15 14:51:10 +00:00
console . log ( curatedQuestions ) ;
2021-11-14 23:38:50 +00:00
console . log ( ` Saved ${ filteredQuestions . length } questions, discarded ${ questions . length - filteredQuestions . length } ` ) ;
2021-11-06 00:33:52 +00:00
}
init ( ) ;