Merge branch 'data-transformation' into main

This commit is contained in:
Ian Cooperman 2022-08-06 16:50:06 -07:00
commit 2c7084028f

View File

@ -1,12 +1,26 @@
// 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) {
// 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},
@ -14,13 +28,40 @@ async function addItem(text) {
title: {
title: [
{
"type": "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("Success! Entry added.");
@ -29,4 +70,4 @@ async function addItem(text) {
}
}
addItem("Yurts in Big Sur, California");
// addItem("Yurts in Big Sur, California");