-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ADD : add retrieve block children features
- Loading branch information
1 parent
983dd6c
commit 3deb359
Showing
5 changed files
with
91 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
""" | ||
Notion API Block | ||
""" | ||
from typing import Dict, List | ||
|
||
from notion_database.components.request import Request | ||
|
||
|
||
class Block: # pylint: disable=too-few-public-methods | ||
""" | ||
Notion API Block class | ||
""" | ||
|
||
def __init__(self, integrations_token: str): | ||
""" | ||
init | ||
:param integrations_token: Notion Internal Integration Token | ||
""" | ||
self.properties_list: List[Dict] = [] | ||
self.url: str = 'https://api.notion.com/v1/blocks' | ||
self.result: Dict = {} | ||
self.request: Request = Request(self.url, integrations_token=integrations_token) | ||
|
||
def retrieve_block(self, block_id: str, is_children: bool = False, | ||
page_size: int = 100, start_cursor: str = None): | ||
""" | ||
Retrieve a block | ||
:param block_id: Identifier for a Notion blocks | ||
:param is_children: Trigger's paginated array of child block objects | ||
:param start_cursor: optional parameter for is_children=True | ||
:param page_size: optional parameter for is_children=True | ||
:return: | ||
""" | ||
if is_children: | ||
param = f"children?page_size={page_size}&start_cursor={start_cursor}" | ||
if start_cursor is None: | ||
param = param.split("&")[0] | ||
self.result = self.request.call_api_get(self.url + "/" + block_id | ||
+ "/" + param) | ||
else: | ||
self.result = self.request.call_api_get(self.url + "/" + block_id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import os | ||
import pprint | ||
|
||
from block import Block | ||
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 | ||
|
||
NOTION_KEY = os.getenv('NOTION_KEY') | ||
|
||
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"] | ||
D = Database(integrations_token=NOTION_KEY) | ||
D.retrieve_database(database_id=database_id) | ||
D.find_all_page(database_id=database_id, page_size=1) | ||
pprint.pprint(D.result) | ||
|
||
B = Block(integrations_token=NOTION_KEY) | ||
for j in D.result["results"]: | ||
B.retrieve_block(block_id=j["id"]) | ||
pprint.pprint(B.result) | ||
# B.retrieve_block(block_id=j["id"], is_children=True) | ||
# pprint.pprint(B.result) | ||
B.retrieve_block(block_id=j["id"], is_children=True, page_size=1) | ||
pprint.pprint(B.result) | ||
# B.retrieve_block(block_id=j["id"],is_children=True, page_size=1, start_cursor=B.result["next_cursor"]) | ||
# pprint.pprint(B.result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters