Skip to content

Commit aba0657

Browse files
committed
Fix content retrieval not working at all
1 parent 30fe319 commit aba0657

File tree

7 files changed

+26
-11
lines changed

7 files changed

+26
-11
lines changed

examples/page.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ async def main():
3131
print(f"├── Title: {page.title}")
3232
print(f"├── ID: {page.id}")
3333
print(f"└── Visit at: {page.url}")
34+
35+
36+
text_content = await page.get_text_content()
37+
print("text_content", text_content )
3438

3539
# Display truncated text content
3640
print("\n📄 Markdown Text Content (Preview):")

examples/page_example.py

Whitespace-only changes.

notionary/blocks/shared/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"purple_background",
3030
"red",
3131
"red_background",
32+
"default_background"
3233
]
3334

3435
BlockType = Literal[
@@ -577,6 +578,8 @@ class Block(BaseModel):
577578
archived: bool = False
578579
in_trash: bool = False
579580
has_children: bool = False
581+
582+
children: Optional[list[Block]] = None # for recursive structure
580583

581584
# Block type-specific content (only one will be populated based on type)
582585
audio: Optional[AudioBlock] = None

notionary/elements/__init__.py

Whitespace-only changes.

notionary/page/content/page_content_retriever.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import json
12
from typing import Any, Dict, Optional
23

34
from notionary.blocks.registry.block_registry import BlockRegistry
45

56
from notionary.blocks import NotionBlockClient
7+
from notionary.blocks.shared.models import Block
68
from notionary.page.notion_to_markdown_converter import (
79
NotionToMarkdownConverter,
810
)
@@ -23,30 +25,36 @@ def __init__(
2325

2426
async def get_page_content(self) -> str:
2527
blocks = await self._get_page_blocks_with_children()
26-
return self._notion_to_markdown_converter.convert(blocks)
28+
29+
# TODO: Fix this quick fix🧯 Quick-Fix: Konvertiere rekursive Block-Objekte in plain dicts
30+
blocks_as_dicts = [block.model_dump(mode="python", exclude_unset=True) for block in blocks]
31+
32+
return self._notion_to_markdown_converter.convert(blocks_as_dicts)
2733

2834
async def _get_page_blocks_with_children(
2935
self, parent_id: Optional[str] = None
30-
) -> list[Dict[str, Any]]:
31-
blocks = (
32-
await self.client.get_page_blocks(page_id=self.page_id)
36+
) -> list[Block]:
37+
response = (
38+
await self.client.get_block_children(block_id=self.page_id)
3339
if parent_id is None
3440
else await self.client.get_block_children(parent_id)
3541
)
3642

37-
if not blocks:
43+
if not response or not response.results:
3844
return []
3945

46+
blocks = response.results
47+
4048
for block in blocks:
41-
if not block.get("has_children"):
49+
if not block.has_children:
4250
continue
4351

44-
block_id = block.get("id")
52+
block_id = block.id
4553
if not block_id:
4654
continue
4755

4856
children = await self._get_page_blocks_with_children(block_id)
4957
if children:
50-
block["children"] = children
58+
block.children = children
5159

52-
return blocks
60+
return blocks

notionary/page/formatting/markdown_to_notion_converter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from notionary.blocks import ColumnElement, BlockRegistry
22
from notionary.page.formatting.line_processor import LineProcessor
33

4-
4+
# TODO: Hier rekursiven Baum Parser verwenden!
55
class MarkdownToNotionConverter:
66
"""Clean converter focused on block identification and conversion"""
77

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "notionary"
3-
version = "0.2.17"
3+
version = "0.2.18"
44
description = "Python library for programmatic Notion workspace management - databases, pages, and content with advanced Markdown support"
55
readme = "README.md"
66
requires-python = ">=3.9"

0 commit comments

Comments
 (0)