Skip to content

Commit 2952d12

Browse files
committed
Revert "Progress towards getting all children"
This reverts commit f814093.
1 parent f814093 commit 2952d12

File tree

2 files changed

+1
-121
lines changed

2 files changed

+1
-121
lines changed

src/_notion_scripts/upload.py

Lines changed: 0 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from ultimate_notion.blocks import Image as UnoImage
1818
from ultimate_notion.blocks import Video as UnoVideo
1919
from ultimate_notion.obj_api.blocks import Block as UnoObjAPIBlock
20-
from ultimate_notion.obj_api.core import Unset, UnsetType
2120

2221

2322
class _SerializedBlockTreeNode(TypedDict):
@@ -121,75 +120,6 @@ def _upload_blocks_recursively(
121120
)
122121

123122

124-
@beartype
125-
def _reconstruct_nested_structure(
126-
*,
127-
items: list[dict[str, Any]],
128-
) -> list[dict[str, Any]]:
129-
"""
130-
Reconstruct nested structure from flattened block items.
131-
"""
132-
result: list[dict[str, Any]] = []
133-
for item in items:
134-
block = item["block"]
135-
block_type = block["type"]
136-
137-
# Handle blocks that can have children
138-
if block_type in {
139-
"paragraph",
140-
"callout",
141-
"bulleted_list_item",
142-
"numbered_list_item",
143-
"toggle",
144-
}:
145-
pass
146-
# children = item.get("children", [])
147-
# nested_blocks = _reconstruct_nested_structure(
148-
# items=children,
149-
# )
150-
# block[block_type]["children"] = nested_blocks
151-
152-
result.append(block)
153-
return result
154-
155-
156-
@beartype
157-
def _sanitize_serialized_block(
158-
*,
159-
serialized_block: dict[str, Any],
160-
) -> dict[str, Any]:
161-
"""
162-
Sanitize a serialized block.
163-
"""
164-
return serialized_block
165-
if isinstance(serialized_block, dict):
166-
return {
167-
key: _sanitize_serialized_block(serialized_block=value)
168-
for key, value in serialized_block.items()
169-
}
170-
return serialized_block
171-
172-
173-
@beartype
174-
def _sanitize_block(
175-
*,
176-
block: Block,
177-
session: Session,
178-
) -> Any:
179-
"""
180-
Sanitize a block.
181-
"""
182-
if block.obj_ref.id and not isinstance(block.obj_ref.id, UnsetType):
183-
block = session.get_block(block_ref=block.obj_ref.id)
184-
block.obj_ref.created_by = Unset
185-
block.obj_ref.last_edited_by = Unset
186-
block.obj_ref.created_time = Unset
187-
block.obj_ref.last_edited_time = Unset
188-
block.obj_ref.id = Unset
189-
block.obj_ref.parent = Unset
190-
return block
191-
192-
193123
@click.command()
194124
@click.option(
195125
"--file",
@@ -255,53 +185,6 @@ def main(
255185

256186
for child in page.children:
257187
child.delete()
258-
block_list = _reconstruct_nested_structure(items=blocks)
259-
block_obj_list = [
260-
Block.wrap_obj_ref(UnoObjAPIBlock.model_validate(obj=block))
261-
for block in block_list
262-
]
263-
sanitized_block_list = [
264-
_sanitize_block(block=block, session=session)
265-
for block in block_obj_list
266-
]
267-
children_list = list(page.children)
268-
sanitized_children_list = [
269-
_sanitize_block(block=child, session=session)
270-
for child in children_list
271-
]
272-
273-
import difflib
274-
import pprint
275-
276-
for index, page_child in enumerate(sanitized_children_list):
277-
block_child = sanitized_block_list[index]
278-
if page_child != block_child:
279-
s1 = pprint.pformat(
280-
page_child.__dict__, sort_dicts=True
281-
).splitlines()
282-
s2 = pprint.pformat(
283-
block_child.__dict__, sort_dicts=True
284-
).splitlines()
285-
286-
diff = difflib.unified_diff(s1, s2)
287-
288-
diff_list = list(diff)
289-
nice_diff = "\n".join(diff)
290-
breakpoint()
291-
# children_obj_list = [
292-
# Block.wrap_obj_ref(UnoObjAPIBlock.model_validate(obj=child))
293-
# for child in children_list
294-
# ]
295-
# serialized_children_list = [
296-
# child.obj_ref.serialize_for_api() for child in children_list
297-
# ]
298-
# sanitized_serialized_children_list = [
299-
# _sanitize_serialized_block(serialized_block=serialized_block)
300-
# for serialized_block in serialized_children_list
301-
# ]
302-
breakpoint()
303-
# for child in page.children:
304-
# child.delete()
305188

306189
# See https://developers.notion.com/reference/request-limits#limits-for-property-values
307190
# which shows that the max number of blocks per request is 100.

src/sphinx_notion/__init__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,14 @@ def _create_rich_text_from_children(*, node: nodes.Element) -> Text:
9292
for child in node.children:
9393
if isinstance(child, nodes.reference):
9494
link_url = child.attributes["refuri"]
95-
assert isinstance(link_url, str)
96-
link_url_with_slash = link_url.rstrip("/") + "/"
9795
link_text = child.attributes.get("name", link_url)
9896

9997
new_text = text(
10098
text=link_text,
101-
href=link_url_with_slash,
99+
href=link_url,
102100
bold=False,
103101
italic=False,
104102
code=False,
105-
color=default_color,
106103
)
107104
elif isinstance(child, nodes.target):
108105
continue

0 commit comments

Comments
 (0)