|
@@ -0,0 +1,28 @@
|
|
|
+import os
|
|
|
+from notion_client import Client
|
|
|
+
|
|
|
+# 1. 获取 token_v2 和 database_id
|
|
|
+token_v2 = "secret_PvJWhkqlZJ7PMIqqPxWDhS736TjvUbkGojyrybjyxNh"
|
|
|
+database_id = "de2ddb5d286e4dffacb1eb26a4e074be"
|
|
|
+
|
|
|
+# 2. 创建 Notion API 客户端对象
|
|
|
+notion = Client(auth=token_v2)
|
|
|
+
|
|
|
+# 3. 连接到 Notion API
|
|
|
+result = notion.databases.retrieve(database_id)
|
|
|
+
|
|
|
+# 4. 查询数据库,并获取满足条件的页面列表
|
|
|
+query = "猫"
|
|
|
+results = notion.search(query=query, filter={"property": "object", "value": "page"}).get("results")
|
|
|
+
|
|
|
+
|
|
|
+def get_title(result):
|
|
|
+ for key, value in result['properties'].items():
|
|
|
+ if value['type'] == "title":
|
|
|
+ return value['title'][0]['plain_text']
|
|
|
+
|
|
|
+
|
|
|
+# 打印满足条件的页面信息
|
|
|
+for result in results:
|
|
|
+ print(f"Page Id: {result['id']}")
|
|
|
+ print(f"Page title: {get_title(result)}")
|