-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
query_db_example.py
46 lines (39 loc) · 1.58 KB
/
query_db_example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import logging
import os
import pprint
from notion_database.const.query import Direction, Timestamp
from notion_database.database import Database
from notion_database.search import Search
try:
from dotenv import load_dotenv
load_dotenv()
except ModuleNotFoundError:
pass
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
NOTION_KEY = os.getenv('NOTION_KEY')
logger.debug("List Database")
S = Search(integrations_token=NOTION_KEY)
S.search_database(query="", sort={"direction": Direction.ascending, "timestamp": Timestamp.last_edited_time})
for i in S.result:
database_id = i["id"]
logger.debug(database_id)
database = Database(integrations_token=NOTION_KEY)
database.run_query_database(database_id=database_id,
db_filter={
"or": [
{
"property": "checkbox",
"checkbox": {
"equals": False
}
},
{
"property": "number",
"number": {
"greater_than_or_equal_to": 2
}
}
]
})
pprint.pprint(database.result)