pashto-grammar/scripts/get-words.js

37 lines
1.0 KiB
JavaScript
Raw Normal View History

2023-02-04 12:20:48 +00:00
import fs from "fs";
import fetch from "node-fetch";
2023-02-04 12:20:48 +00:00
import nounAdjTs from "../src/words/nouns-adjs.js";
import verbs from "../src/words/verbs.js";
import adverbs from "../src/words/adverbs.js";
2023-02-04 12:20:48 +00:00
const wordsFile = "./src/words/raw-words.ts";
2021-03-06 10:40:31 +00:00
2023-02-04 12:20:48 +00:00
const allTs = [...nounAdjTs, ...verbs, ...adverbs];
2021-03-06 10:40:31 +00:00
console.log("getting words from dictionary...");
2022-11-02 06:08:24 +00:00
fetch("https://account.lingdocs.com/dictionary/entries", {
2023-07-27 18:53:03 +00:00
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ ids: allTs }),
})
.then((res) => res.json())
.then((data) => {
const content = `
2021-10-18 01:12:47 +00:00
// @ts-ignore
2022-11-02 06:08:24 +00:00
const words: Word[] = ${JSON.stringify(data.results)};
2021-10-18 01:12:47 +00:00
export default words;`;
2023-07-27 18:53:03 +00:00
fs.writeFileSync(wordsFile, content);
const missingEc = data.results.filter((x) => "entry" in x && !x.entry.ec);
if (missingEc.length) {
console.log("verbs missing ec");
console.log(missingEc);
}
if (data.notFound.length) {
console.log("entries not found:");
console.log(data.notFound);
}
});