-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexegesis_script.mjs
47 lines (46 loc) · 1.26 KB
/
exegesis_script.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
40
41
42
43
44
45
46
47
import pg from "pg";
import dotenv from "dotenv";
import fs from "fs";
dotenv.config();
const { Client } = pg;
const config = {
host: process.env.DB_HOST,
port: process.env.DB_PORT,
user: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_DB,
};
const client = new Client(config);
await client.connect();
const nicks_id = process.env.NICK_ID;
const { rows } = await client.query(
`
SELECT note_id, private_content.* FROM private_content LEFT JOIN private_notes ON slate_parent = private_notes.note_id
WHERE private_notes.author=$1 AND private_content.slate_parent IS NOT NULL ORDER BY slate_index ASC;
`,
[nicks_id]
);
// console.dir(rows, { depth: null });
// next, parse into text and save as text file
try {
fs.rmSync("./exegesis", { recursive: true, force: true });
} finally {
fs.mkdirSync("./exegesis");
process.chdir("./exegesis");
}
for (const row of rows) {
const { slate_content } = row;
const str_content = slate_content?.children
?.map((node) => {
if (node.type === "mention") {
return `[[${row.tags?.[node.value]}]]`;
}
return node?.text || "";
})
.join("");
() => {
console.log(str_content);
};
fs.appendFileSync(`${row.note_id}.txt`, `\n${str_content}`);
}
process.exit(0);