-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextractTestInputs
executable file
·49 lines (43 loc) · 1.09 KB
/
extractTestInputs
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
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/node
import { writeFileSync } from "fs";
import { JSDOM } from "jsdom";
const url = process.argv[2];
const day = process.argv[3];
const text = await (
await fetch(url, {
headers: {
"User-Agent": "github.com/guillaumebrunerie/advent-of-code-2024",
},
})
).text();
const dom = new JSDOM(text);
const testInputs = [];
for (const pre of dom.window.document.querySelectorAll("pre")) {
const testInput = pre.textContent;
if (!testInputs.includes(testInput)) {
testInputs.push(testInput);
}
}
if (testInputs.length == 1) {
const testInput = testInputs[0];
writeFileSync(`${day}/testInput.txt`, testInput);
process.stderr.write(`
Test input:
${testInput}
`);
console.log(`\t{ file: "${day}/testInput", label: "Test input" },`);
} else {
testInputs.forEach((testInput, i) => {
writeFileSync(`${day}/testInput${i + 1}.txt`, testInput);
process.stderr.write(`
Test input #${i + 1}:
${testInput}
`);
process.stdout.write(
`\t{ file: "${day}/testInput${i + 1}", label: "Test input #${i + 1}" },`,
);
if (i < testInputs.length - 1) {
process.stdout.write("\\n");
}
});
}