name: notion-helper description: Notion API助手 - 建立和管理Notion頁面、資料庫,支援筆記和知識管理。 metadata: {"openclaw": {"requires": {"python": ["notion-client"]}, "install": []}} tags: [notion, notes, database, knowledge, api] version: 1.0.0 author: laosi source: adapted
啟用詞: Notion / 筆記管理 / 知識庫
pip install notion-client
from notion_client import AsyncClient
import asyncio
class NotionHelper:
def __init__(self, token: str):
self.client = AsyncClient(auth=token)
async def create_page(self, parent_id: str, title: str, content: str = ""):
await self.client.pages.create(
parent={"database_id": parent_id},
properties={
"title": {
"title": [{"text": {"content": title}}]
}
},
children=[{
"object": "block",
"type": "paragraph",
"paragraph": {
"rich_text": [{"type": "text", "text": {"content": content}}]
}
}]
)
async def query_database(self, db_id: str, filter_props: dict = None):
params = {"database_id": db_id}
if filter_props:
params["filter"] = filter_props
return await self.client.databases.query(**params)
async def update_page(self, page_id: str, properties: dict):
await self.client.pages.update(page_id, properties=properties)
async def get_page(self, page_id: str):
return await self.client.pages.retrieve(page_id)
async def search(self, query: str):
return await self.client.search(query)
async def main():
helper = NotionHelper("secret_xxx")
# 建立頁面
await helper.create_page(
parent_id="database_id",
title="AI學習筆記",
content="今天學習了機器學習..."
)
# 搜尋頁面
results = await helper.search("AI")
for page in results['results']:
print(page['title'])
# 查詢資料庫
pages = await helper.query_database("database_id")
for page in pages['results']:
print(page['properties']['title']['title'][0]['text']['content'])
asyncio.run(main())
| 型別 | 說明 |
|---|---|
| title | 標題 |
| rich_text | 文本 |
| number | 數字 |
| checkbox | 核取方塊 |
| select | 單選 |
| multi_select | 多選 |
| date | 日期 |
| url | 連結 |
| 郵箱 | |
| phone_number | 電話 |
本技能來自小蔥技能站7w4.net。
這個工具能幫助管理Notion筆記,提供了基本的操作指南,質量中等偏上。優點是文件清晰完整,功能覆蓋面全,有實際可參考的使用示例。不足之處在於程式碼以示例為主,缺少完整實現檔案,高階功能支援有限。對於想快速上手Notion API的使用者來說有一定參考價值,但複雜場景下可能需要額外學習。適合作為入門級參考,但深度和實用性有待提升。