Skip to content

Instantly share code, notes, and snippets.

@azu
Created January 1, 2023 06:36
Show Gist options
  • Save azu/c9a93bff3f0620d10894d6842cd91e12 to your computer and use it in GitHub Desktop.
Save azu/c9a93bff3f0620d10894d6842cd91e12 to your computer and use it in GitHub Desktop.
notion-daily-generator.mjs
import { Client } from "@notionhq/client"
import dayjs from "dayjs"
const notion = new Client({
auth: process.env.NOTION_API_TOKEN,
});
/**
*
* @param {title} title
* @param {string} date
* @param {{name:string;}} multi_select
*/
const createPage = ({ title, date, select }) => {
return notion.pages.create({
parent: {
type: "database_id",
database_id: process.env.NOTION_DATABASE_ID,
},
properties: {
Name: {
title: [
{
"text": {
content: title,
}
}
],
},
Date: {
type: "date",
date: {
start: date,
}
},
Type: {
type: 'select',
select: select
}
}
})
}
/**
* @type {({ title:string; select: {name:string;}})[]}
*/
const CREATE_LIST = Array.from({ length: 365 }).flatMap((_, i) => {
const day = dayjs().add(i, "day").format('YYYY/MM/DD');
const date = dayjs().add(i, "day").format('YYYY-MM-DD');
return [
{
title: day,
date: date,
select: {
name: 'タスク'
}
}
]
});
for (const item of CREATE_LIST) {
await createPage(item);
console.log("Created: " + item.title)
await new Promise((resolve) => setTimeout(resolve, 1000));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment