-
Notifications
You must be signed in to change notification settings - Fork 1
/
split.mjs
39 lines (34 loc) · 926 Bytes
/
split.mjs
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
import Papa from 'papaparse';
import { createReadStream } from 'fs';
import { writeFile, mkdir } from 'fs/promises';
import { pick } from 'lodash-es';
const inputStream = createReadStream('./questions.csv');
Papa.parse(inputStream, {
worker: true,
header: true,
complete: async (results) => {
const shows = new Map();
for (const question of results.data) {
if (!shows.has(question.showNumber)) {
shows.set(question.showNumber, []);
}
shows
.get(question.showNumber)
.push(
pick(question, ['round', 'category', 'value', 'question', 'answer'])
);
}
await mkdir('./trivia/shows', {
recursive: true
});
for (const [showNumber, questions] of shows.entries()) {
await writeFile(
`./trivia/shows/${showNumber}.json`,
JSON.stringify({
showNumber,
questions
})
);
}
}
});