fei*_*ong 15 python notion-api
我有一些 Python 代码,可以使用notion-client 库检索 Notion 数据库中的行。该代码确实设法检索所有行,但顺序错误。我查看了API 参考中的Sort 对象,但无法弄清楚如何使用它以行在 notion.so 上显示的确切顺序返回行。这是有问题的片段:
from notion_client import Client
notion = Client(auth=NOTION_API_TOKEN)
result = notion.databases.query(database_id='...')
for row in result['results']:
title = row['properties']['NAME_OF_PROPERTY']['title']
if len(title) == 0:
print('')
else:
print(title[0]['plain_text'])
Run Code Online (Sandbox Code Playgroud)
我缺少什么?
Bar*_*mar -1
使用order参数notion.databases.query(). 该参数是排序规范的列表,即字典。
result = notion.databases.query(
database_id = 'df4dfb3f-f36f-462d-ad6e-1ef29f1867eb',
sort = [{"property": "NAME_OF_PROPERTY", "direction": "ascending"}]
)
Run Code Online (Sandbox Code Playgroud)
您可以在列表中放置多个排序规范,后面的排序规范将用于前面属性相同的行。