Merge branch 'data-transformation' into main
This commit is contained in:
commit
2c7084028f
59
index.js
59
index.js
|
|
@ -1,12 +1,26 @@
|
||||||
// import variables from `.env`
|
// import variables from `.env`
|
||||||
require('dotenv').config();
|
import 'dotenv/config'
|
||||||
const { Client } = require('@notionhq/client');
|
import { Client } from '@notionhq/client'
|
||||||
|
import Joplin from './joplin.js'
|
||||||
|
|
||||||
const notion = new Client({auth: process.env.NOTION_KEY});
|
const joplin = new Joplin(process.env.JOPLIN_TOKEN, process.env.JOPLIN_CLIPPER_PORT)
|
||||||
|
const notion = new Client({auth: process.env.NOTION_TOKEN});
|
||||||
|
const joplinNotebookID = process.env.JOPLIN_NOTEBOOK_ID;
|
||||||
|
const notionDatabaseID = process.env.NOTION_DATABASE_ID;
|
||||||
|
|
||||||
const databaseID = process.env.NOTION_DATABASE_ID;
|
|
||||||
|
|
||||||
async function addItem(text) {
|
// essentially a main function
|
||||||
|
async function processNotes() {
|
||||||
|
const data = await joplin.getNotesFromNotebook(joplinNotebookID, ["title", "body", "created_time", "updated_time"])
|
||||||
|
for (let note of data) {
|
||||||
|
addPageToNotionDatabase(notionDatabaseID, note.title, note.body)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
processNotes()
|
||||||
|
|
||||||
|
|
||||||
|
async function addPageToNotionDatabase(databaseID, title, body) {
|
||||||
try {
|
try {
|
||||||
const response = await notion.pages.create({
|
const response = await notion.pages.create({
|
||||||
parent: {database_id: databaseID},
|
parent: {database_id: databaseID},
|
||||||
|
|
@ -14,13 +28,40 @@ async function addItem(text) {
|
||||||
title: {
|
title: {
|
||||||
title: [
|
title: [
|
||||||
{
|
{
|
||||||
|
"type": "text",
|
||||||
"text": {
|
"text": {
|
||||||
"content": text
|
"content": title,
|
||||||
}
|
"link": null
|
||||||
}
|
},
|
||||||
|
"annotations": {
|
||||||
|
"bold": false,
|
||||||
|
"italic": false,
|
||||||
|
"strikethrough": false,
|
||||||
|
"underline": false,
|
||||||
|
"code": false,
|
||||||
|
"color": "default"
|
||||||
|
},
|
||||||
|
"plain_text": "Grocery List",
|
||||||
|
"href": null
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
object: "block",
|
||||||
|
type: "paragraph",
|
||||||
|
paragraph: {
|
||||||
|
"rich_text": [
|
||||||
|
{
|
||||||
|
"text": {
|
||||||
|
"content": body
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
})
|
})
|
||||||
console.log(response);
|
console.log(response);
|
||||||
console.log("Success! Entry added.");
|
console.log("Success! Entry added.");
|
||||||
|
|
@ -29,4 +70,4 @@ async function addItem(text) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addItem("Yurts in Big Sur, California");
|
// addItem("Yurts in Big Sur, California");
|
||||||
Loading…
Reference in New Issue