feat(notion): 添加Notion数据库集成功能和相关脚本
添加Notion数据库集成配置和访问脚本,包括: - 配置Notion MCP服务器设置 - 添加数据库查询、内容查看和添加功能 - 创建测试脚本和集成文档
This commit is contained in:
85
add_notion_content.py
Normal file
85
add_notion_content.py
Normal file
@@ -0,0 +1,85 @@
|
||||
"""
|
||||
Script to add sample content to your Notion database
|
||||
"""
|
||||
|
||||
import requests
|
||||
import json
|
||||
|
||||
class NotionDatabaseUpdater:
|
||||
def __init__(self, integration_token="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"):
|
||||
self.integration_token = integration_token
|
||||
self.headers = {
|
||||
"Authorization": f"Bearer {integration_token}",
|
||||
"Content-Type": "application/json",
|
||||
"Notion-Version": "2022-06-28"
|
||||
}
|
||||
self.base_url = "https://api.notion.com/v1"
|
||||
|
||||
def create_page_in_database(self, database_id, page_title, additional_properties=None):
|
||||
"""Create a new page in the specified database"""
|
||||
url = f"{self.base_url}/pages"
|
||||
|
||||
# Basic structure for a page with a title
|
||||
data = {
|
||||
"parent": {"database_id": database_id},
|
||||
"properties": {
|
||||
"名称": { # Assuming "名称" is the title property based on our earlier discovery
|
||||
"title": [
|
||||
{
|
||||
"text": {
|
||||
"content": page_title
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Add any additional properties if provided
|
||||
if additional_properties:
|
||||
for prop_name, prop_value in additional_properties.items():
|
||||
data["properties"][prop_name] = prop_value
|
||||
|
||||
response = requests.post(url, headers=self.headers, json=data)
|
||||
if response.status_code == 200:
|
||||
return response.json()
|
||||
else:
|
||||
print(f"Error creating page: {response.status_code} - {response.text}")
|
||||
return None
|
||||
|
||||
def main():
|
||||
# Initialize the updater
|
||||
updater = NotionDatabaseUpdater()
|
||||
|
||||
# Use the database ID we found earlier
|
||||
database_id = "2fbdaaa6-ba07-804a-b48a-ce9c0a107416"
|
||||
|
||||
# Create a sample page
|
||||
sample_pages = [
|
||||
{
|
||||
"title": "今天的工作计划",
|
||||
"properties": {}
|
||||
},
|
||||
{
|
||||
"title": "学习新技能",
|
||||
"properties": {}
|
||||
},
|
||||
{
|
||||
"title": "项目进展",
|
||||
"properties": {}
|
||||
}
|
||||
]
|
||||
|
||||
print("正在向您的 Notion 数据库添加示例内容...")
|
||||
|
||||
for page in sample_pages:
|
||||
print(f"添加页面: {page['title']}")
|
||||
result = updater.create_page_in_database(database_id, page['title'], page['properties'])
|
||||
if result:
|
||||
print(f" ✓ 页面创建成功! 页面ID: {result['id']}")
|
||||
else:
|
||||
print(f" ✗ 页面创建失败")
|
||||
print()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user