LoginSignup
11
8

More than 3 years have passed since last update.

Create Page/Todo Block with Notion API

Last updated at Posted at 2020-01-15

notion-banner.png

How to add a Page / Todo block with the Notion API call.
I used https://github.com/jamalex/notion-py

☕️ Ex) Starbucks man drinks nine o'clock every morning and check.

Ready

  • python v3.5 ↑
  • token_v2 ✅ Notion web login -> F12 -> Application -> Cookies -> token_v2 notion00.png

Start

1. Pre installation

$ pip install notion

2. Source code

add_childpage.py

$ vi add_childpage.py
from notion.client import NotionClient
from notion.block import TodoBlock
from notion.block import PageBlock

# login
token_v2 = 'c6c629d29504bd10272...012345678901234512345' # 준비물의 token_v2
client = NotionClient(token_v2=token_v2)

# 스벅남 페이지 URL
url = "https://www.notion.so/openwiki/d8e3e99628eb4e21a258575367ee72c5"
page = client.get_block(url)

print("Page 제목은  :", page.title)

################################
# API 호출로 PageBlock 추가
################################
print(page.children.add_new(PageBlock, title='2020.01.11'))
print(page.children.add_new(PageBlock, title='2020.01.12'))
print(page.children.add_new(PageBlock, title='2020.01.13'))
print(page.children.add_new(PageBlock, title='2020.01.14'))
print(page.children.add_new(PageBlock, title='2020.01.15'))

####################################
# PageBlock에 TodoBlock 추가
####################################
for child in page.children :
    child_page = client.get_block(child.id)
    child_page.children.add_new(TodoBlock, title="09:00 아아벤티")

3. Run

$ python ./add_childpage.py

4. Result

notion01.jpg
notion02.jpg
notion03.jpg

Etc

11
8
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
8