Skip to content

Commit 2a2ea85

Browse files
committed
Added import status
1 parent ef8e3ae commit 2a2ea85

File tree

4 files changed

+183
-7
lines changed

4 files changed

+183
-7
lines changed

package-lock.json

Lines changed: 149 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"author": "",
1212
"license": "ISC",
1313
"dependencies": {
14-
"@tryfabric/martian": "^1.2.4"
14+
"@tryfabric/martian": "^1.2.4",
15+
"pg": "^8.11.3"
1516
}
1617
}

src/db.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import pg from 'pg'
2+
3+
const pool = new pg.Pool({
4+
host: 'localhost',
5+
database: 'notion',
6+
user: 'phpusr'
7+
})
8+
9+
//await addNoteInfo({ title: 'test', filePath: 'testpath', imported: true })
10+
11+
export async function addNoteInfo({ noteId, title, filePath, imported, error }) {
12+
const text = 'INSERT INTO imported_notes(note_id, title, file_path, imported, error) VALUES($1, $2, $3, $4, $5)'
13+
const values = [noteId, title, filePath, imported, error]
14+
const res = await pool.query(text, values)
15+
console.log(res)
16+
}
17+

src/index.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import { readdirSync, readFileSync, lstatSync } from 'node:fs'
2-
import { markdownToBlocks, markdownToRichText } from '@tryfabric/martian'
1+
import { lstatSync, readdirSync, readFileSync } from 'node:fs'
2+
import { markdownToBlocks } from '@tryfabric/martian'
33
import { addBlocks, createPage } from './notion_api.js'
4+
import { addNoteInfo } from './db.js'
45

56

67
await importNotes()
78

89
async function importNotes() {
910
const notesDir = '/home/phpusr/tmp/notes/NOTES/car';
10-
const files = readdirSync(notesDir, {recursive: true}).slice(0, 2)
11+
const files = readdirSync(notesDir, {recursive: true}).slice(0, 6)
1112

1213
for (const relFilePath of files) {
1314
const filePath = `${notesDir}/${relFilePath}`
@@ -29,11 +30,20 @@ async function importNotes() {
2930
console.log(`\n${relFilePath}`)
3031
console.log('-'.repeat(30) + '\n')
3132
//console.log(data);
33+
34+
const noteInfo = { noteId: page.id, title: relFilePath, filePath: relFilePath }
35+
3236
const blocks = markdownToBlocks(data)
3337
try {
34-
const res = await addBlocks({parentId: page.id, blocks})
38+
await addBlocks({ parentId: page.id, blocks })
39+
noteInfo.imported = true
3540
} catch (e) {
36-
console.error('ERROR', JSON.stringify(e))
41+
noteInfo.imported = false
42+
noteInfo.error = JSON.stringify(e)
43+
console.error('ERROR')
3744
}
45+
46+
await addNoteInfo(noteInfo)
3847
}
3948
}
49+

0 commit comments

Comments
 (0)