Skip to content

Commit 58ad1ce

Browse files
authored
Add support for blocks (lolipopshock#31)
* making progress on adding blocks * more progress on blocks * Add parse_blocks * add download_page_children * Better README
1 parent 288480c commit 58ad1ce

File tree

4 files changed

+355
-4
lines changed

4 files changed

+355
-4
lines changed

README.md

+27-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# `notion-df`: Seamlessly Connecting Notion Database with Pandas DataFrame
22

3-
*Please Note: This project is currently in pre-alpha stage. The code are not appropriately documented and tested. Please report any issues you find.*
3+
*Please Note: This project is currently in pre-alpha stage. The code are not appropriately documented and tested. Please report any issues you find. Thanks!*
44

55
## Installation
66

@@ -83,6 +83,32 @@ pip install notion-df
8383
# Similarly in pandas APIs: df.to_notion(notion_page_url, title="page-title")
8484
```
8585

86+
## Development
87+
88+
1. Clone the repo and install the dependencies:
89+
```bash
90+
git clone git@github.com:lolipopshock/notion-df.git
91+
cd notion-df
92+
pip install -e .[dev]
93+
```
94+
2. How to run tests?
95+
```bash
96+
NOTION_API_KEY="<the-api-key>" pytest tests/
97+
```
98+
The tests are dependent on a list of notebooks, specified by the following environment variables:
99+
100+
| Environment Variable | Description |
101+
| --------------------------- | --------------------------------------- |
102+
| `NOTION_API_KEY` | The API key for your Notion integration |
103+
| `NOTION_ROLLUP_DF` | - |
104+
| `NOTION_FILES_DF` | - |
105+
| `NOTION_FORMULA_DF` | - |
106+
| `NOTION_RELATION_DF` | - |
107+
| `NOTION_RELATION_TARGET_DF` | - |
108+
| `NOTION_LONG_STRING_DF` | - |
109+
| `NOTION_RICH_TEXT_DF` | - |
110+
111+
86112
## TODOs
87113

88114
- [ ] Add tests for

src/notion_df/agent.py

+23
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from notion_df.values import PageProperties, PageProperty
1313
from notion_df.configs import DatabaseSchema, NON_EDITABLE_TYPES
1414
from notion_df.utils import is_uuid
15+
from notion_df.blocks import parse_blocks
1516

1617
API_KEY = None
1718
NOT_REVERSE_DATAFRAME = -1
@@ -437,3 +438,25 @@ def upload(
437438
if return_response:
438439
return notion_url, response
439440
return notion_url
441+
442+
@use_client
443+
def download_page_children(
444+
notion_url: str,
445+
api_key: str = None,
446+
client: Client = None,
447+
):
448+
"""Download the children of a Notion page.
449+
450+
Args:
451+
notion_url (str):
452+
The url of the Notion page.
453+
api_key (str, optional):
454+
The API key of the Notion integration.
455+
Defaults to None.
456+
client (Client, optional):
457+
The notion client.
458+
Defaults to None.
459+
"""
460+
page_id = get_id(notion_url)
461+
r = client.blocks.children.list(block_id=page_id)
462+
return parse_blocks(r['results'], recursive=True, client=client)

src/notion_df/base.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def value(self):
216216

217217

218218
class FileObject(BaseModel):
219-
name: str
219+
name: Optional[str] #TODO: Figure out why this is not required...
220220
type: str
221221
file: Optional[FileTargetObject]
222222
external: Optional[FileTargetObject]
@@ -297,7 +297,7 @@ class BaseRichTextObject(BaseModel):
297297
href: Optional[str] = None
298298
annotations: Optional[AnnotationObject] = None
299299
type: Optional[RichTextTypeEnum]
300-
300+
301301
@property
302302
def value(self):
303303
return self.plain_text
@@ -318,4 +318,9 @@ def encode_string(cls, value: str) -> List["RichTextObject"]:
318318
return [
319319
cls(text=TextObject(content=value[idx : idx + chunk_size]))
320320
for idx in range(0, len(value), chunk_size)
321-
]
321+
]
322+
323+
324+
class EmojiObject(BaseModel):
325+
type: str = "emoji"
326+
emoji: str

0 commit comments

Comments
 (0)