-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
80 lines (77 loc) · 1.97 KB
/
index.js
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { readFile } from "fs";
import dotenv from "dotenv";
dotenv.config();
import { Client, APIErrorCode } from "@notionhq/client";
const notion = new Client({ auth: process.env.TOKEN });
const databaseId = process.env.DATABASE_ID;
async function addEntry(title, clips, author, dataAddet) {
try {
const response = await notion.pages.create({
parent: { database_id: databaseId },
properties: {
"Clippings": {
"rich_text": [
{
"type": "text",
"text": {
"content": clips
}
}
]
},
"Date Clipped": {
"rich_text": [
{
"type": "text",
"text": {
"content": dataAddet
}
}
]
},
"Author": {
"rich_text": [
{
"type": "text",
"text": {
"content": author
}
}
]
},
title: {
title:[
{
"text": {
"content": title
}
}
]
}
},
})
console.log(response)
console.log("Success! Entry added.")
} catch (error) {
console.error(error.body)
}
}
var clippings = readFile('./My Clippings.txt', 'utf-8', (err, data) => {
if (err) {
console.error(err);
}
const ctx = new String(data).split('==========');
for(var i = 0; i<=(ctx.length-2); i++){
var ctn = String(ctx[i]).replace("(German Edition) ")
var title = new String(ctn).split("(")[0]
var author = new String(ctn).split("(")[2].split(")")[0]
var dataAddet = new String(ctn).split("|")[2].split("\n")[0]
if(new String(ctn).split(":")[3] != undefined){
var clip = new String(ctx[i]).split(":")[3];
} else {
var clip = new String(ctn).split(":")[2]
}
var clip = clip.slice(6);
addEntry(title, clip, author, dataAddet)
}
});