add data generation script
This commit is contained in:
parent
241bcd29e3
commit
fbfcd43799
1 changed files with 23 additions and 0 deletions
23
data/generate.ts
Executable file
23
data/generate.ts
Executable file
|
@ -0,0 +1,23 @@
|
|||
#!/usr/bin/env -S deno run --allow-read --allow-write
|
||||
|
||||
import { join } from "https://deno.land/std@0.224.0/path/join.ts";
|
||||
import { dirname } from "https://deno.land/std@0.224.0/path/dirname.ts";
|
||||
|
||||
async function main() {
|
||||
const script_path = new URL(import.meta.url).pathname;
|
||||
const data_dir = dirname(script_path);
|
||||
|
||||
for await (const entry of Deno.readDir(data_dir)) {
|
||||
if (!entry.isFile) continue;
|
||||
if (!entry.name.endsWith("txt")) continue;
|
||||
|
||||
const content = await Deno.readTextFile(join(data_dir, entry.name));
|
||||
const lines = content.split("\n").map((l) => l.trim());
|
||||
|
||||
const json_path = join(data_dir, entry.name + ".json");
|
||||
const serialized = JSON.stringify(lines, null, 2);
|
||||
await Deno.writeTextFile(json_path, serialized);
|
||||
}
|
||||
}
|
||||
|
||||
if (import.meta.main) await main();
|
Loading…
Add table
Add a link
Reference in a new issue