From b3fe8075f5bbdaae1de9995146cd205a36665051 Mon Sep 17 00:00:00 2001 From: Ian Cooperman Date: Thu, 4 Aug 2022 20:00:18 -0700 Subject: [PATCH 1/2] Cleaned up index.js before continuing --- index.js | 58 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/index.js b/index.js index 5b61ab7..0093dfc 100644 --- a/index.js +++ b/index.js @@ -1,32 +1,34 @@ // import variables from `.env` -require('dotenv').config(); -const { Client } = require('@notionhq/client'); +import 'dotenv/config' +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) { +// try { +// const response = await notion.pages.create({ +// parent: {database_id: databaseID}, +// properties: { +// title: { +// title: [ +// { +// "text": { +// "content": text +// } +// } +// ] +// } +// }, +// }) +// console.log(response); +// console.log("Success! Entry added."); +// } catch (error) { +// console.error(error.body); +// } +// } -async function addItem(text) { - try { - const response = await notion.pages.create({ - parent: {database_id: databaseID}, - properties: { - title: { - title: [ - { - "text": { - "content": text - } - } - ] - } - }, - }) - console.log(response); - console.log("Success! Entry added."); - } catch (error) { - console.error(error.body); - } -} - -addItem("Yurts in Big Sur, California"); \ No newline at end of file +// addItem("Yurts in Big Sur, California"); \ No newline at end of file From 876c74ba41b489ea5e78fc902b0d3d5f57460d94 Mon Sep 17 00:00:00 2001 From: Ian Cooperman Date: Sat, 6 Aug 2022 16:37:12 -0700 Subject: [PATCH 2/2] Wrote rudimentary creation of Notion pages with title and body --- index.js | 83 +++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 61 insertions(+), 22 deletions(-) diff --git a/index.js b/index.js index 0093dfc..3f29711 100644 --- a/index.js +++ b/index.js @@ -8,27 +8,66 @@ const notion = new Client({auth: process.env.NOTION_TOKEN}); const joplinNotebookID = process.env.JOPLIN_NOTEBOOK_ID; const notionDatabaseID = process.env.NOTION_DATABASE_ID; -// async function addItem(text) { -// try { -// const response = await notion.pages.create({ -// parent: {database_id: databaseID}, -// properties: { -// title: { -// title: [ -// { -// "text": { -// "content": text -// } -// } -// ] -// } -// }, -// }) -// console.log(response); -// console.log("Success! Entry added."); -// } catch (error) { -// console.error(error.body); -// } -// } + +// 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 { + const response = await notion.pages.create({ + parent: {database_id: databaseID}, + properties: { + title: { + title: [ + { + "type": "text", + "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("Success! Entry added."); + } catch (error) { + console.error(error.body); + } +} // addItem("Yurts in Big Sur, California"); \ No newline at end of file