notionary 0.1.27__tar.gz → 0.1.29__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. {notionary-0.1.27 → notionary-0.1.29}/PKG-INFO +1 -1
  2. {notionary-0.1.27 → notionary-0.1.29}/notionary/page/content/page_content_manager.py +41 -10
  3. {notionary-0.1.27 → notionary-0.1.29}/notionary/page/metadata/notion_icon_manager.py +3 -3
  4. {notionary-0.1.27 → notionary-0.1.29}/notionary/page/metadata/notion_page_cover_manager.py +11 -1
  5. {notionary-0.1.27 → notionary-0.1.29}/notionary/page/notion_page.py +2 -2
  6. {notionary-0.1.27 → notionary-0.1.29}/notionary.egg-info/PKG-INFO +1 -1
  7. {notionary-0.1.27 → notionary-0.1.29}/setup.py +1 -1
  8. {notionary-0.1.27 → notionary-0.1.29}/LICENSE +0 -0
  9. {notionary-0.1.27 → notionary-0.1.29}/README.md +0 -0
  10. {notionary-0.1.27 → notionary-0.1.29}/notionary/__init__.py +0 -0
  11. {notionary-0.1.27 → notionary-0.1.29}/notionary/database/database_discovery.py +0 -0
  12. {notionary-0.1.27 → notionary-0.1.29}/notionary/database/database_info_service.py +0 -0
  13. {notionary-0.1.27 → notionary-0.1.29}/notionary/database/models/page_result.py +0 -0
  14. {notionary-0.1.27 → notionary-0.1.29}/notionary/database/notion_database.py +0 -0
  15. {notionary-0.1.27 → notionary-0.1.29}/notionary/database/notion_database_factory.py +0 -0
  16. {notionary-0.1.27 → notionary-0.1.29}/notionary/elements/audio_element.py +0 -0
  17. {notionary-0.1.27 → notionary-0.1.29}/notionary/elements/bookmark_element.py +0 -0
  18. {notionary-0.1.27 → notionary-0.1.29}/notionary/elements/bulleted_list_element.py +0 -0
  19. {notionary-0.1.27 → notionary-0.1.29}/notionary/elements/callout_element.py +0 -0
  20. {notionary-0.1.27 → notionary-0.1.29}/notionary/elements/code_block_element.py +0 -0
  21. {notionary-0.1.27 → notionary-0.1.29}/notionary/elements/divider_element.py +0 -0
  22. {notionary-0.1.27 → notionary-0.1.29}/notionary/elements/embed_element.py +0 -0
  23. {notionary-0.1.27 → notionary-0.1.29}/notionary/elements/heading_element.py +0 -0
  24. {notionary-0.1.27 → notionary-0.1.29}/notionary/elements/image_element.py +0 -0
  25. {notionary-0.1.27 → notionary-0.1.29}/notionary/elements/mention_element.py +0 -0
  26. {notionary-0.1.27 → notionary-0.1.29}/notionary/elements/notion_block_element.py +0 -0
  27. {notionary-0.1.27 → notionary-0.1.29}/notionary/elements/numbered_list_element.py +0 -0
  28. {notionary-0.1.27 → notionary-0.1.29}/notionary/elements/paragraph_element.py +0 -0
  29. {notionary-0.1.27 → notionary-0.1.29}/notionary/elements/prompts/element_prompt_content.py +0 -0
  30. {notionary-0.1.27 → notionary-0.1.29}/notionary/elements/prompts/synthax_prompt_builder.py +0 -0
  31. {notionary-0.1.27 → notionary-0.1.29}/notionary/elements/qoute_element.py +0 -0
  32. {notionary-0.1.27 → notionary-0.1.29}/notionary/elements/registry/block_element_registry.py +0 -0
  33. {notionary-0.1.27 → notionary-0.1.29}/notionary/elements/registry/block_element_registry_builder.py +0 -0
  34. {notionary-0.1.27 → notionary-0.1.29}/notionary/elements/table_element.py +0 -0
  35. {notionary-0.1.27 → notionary-0.1.29}/notionary/elements/text_inline_formatter.py +0 -0
  36. {notionary-0.1.27 → notionary-0.1.29}/notionary/elements/todo_element.py +0 -0
  37. {notionary-0.1.27 → notionary-0.1.29}/notionary/elements/toggle_element.py +0 -0
  38. {notionary-0.1.27 → notionary-0.1.29}/notionary/elements/toggleable_heading_element.py +0 -0
  39. {notionary-0.1.27 → notionary-0.1.29}/notionary/elements/video_element.py +0 -0
  40. {notionary-0.1.27 → notionary-0.1.29}/notionary/exceptions/database_exceptions.py +0 -0
  41. {notionary-0.1.27 → notionary-0.1.29}/notionary/exceptions/page_creation_exception.py +0 -0
  42. {notionary-0.1.27 → notionary-0.1.29}/notionary/notion_client.py +0 -0
  43. {notionary-0.1.27 → notionary-0.1.29}/notionary/page/content/notion_page_content_chunker.py +0 -0
  44. {notionary-0.1.27 → notionary-0.1.29}/notionary/page/markdown_to_notion_converter.py +0 -0
  45. {notionary-0.1.27 → notionary-0.1.29}/notionary/page/metadata/metadata_editor.py +0 -0
  46. {notionary-0.1.27 → notionary-0.1.29}/notionary/page/notion_page_factory.py +0 -0
  47. {notionary-0.1.27 → notionary-0.1.29}/notionary/page/notion_to_markdown_converter.py +0 -0
  48. {notionary-0.1.27 → notionary-0.1.29}/notionary/page/properites/database_property_service.py +0 -0
  49. {notionary-0.1.27 → notionary-0.1.29}/notionary/page/properites/page_property_manager.py +0 -0
  50. {notionary-0.1.27 → notionary-0.1.29}/notionary/page/properites/property_formatter.py +0 -0
  51. {notionary-0.1.27 → notionary-0.1.29}/notionary/page/properites/property_operation_result.py +0 -0
  52. {notionary-0.1.27 → notionary-0.1.29}/notionary/page/properites/property_value_extractor.py +0 -0
  53. {notionary-0.1.27 → notionary-0.1.29}/notionary/page/relations/notion_page_relation_manager.py +0 -0
  54. {notionary-0.1.27 → notionary-0.1.29}/notionary/page/relations/notion_page_title_resolver.py +0 -0
  55. {notionary-0.1.27 → notionary-0.1.29}/notionary/page/relations/page_database_relation.py +0 -0
  56. {notionary-0.1.27 → notionary-0.1.29}/notionary/page/relations/relation_operation_result.py +0 -0
  57. {notionary-0.1.27 → notionary-0.1.29}/notionary/util/logging_mixin.py +0 -0
  58. {notionary-0.1.27 → notionary-0.1.29}/notionary/util/page_id_utils.py +0 -0
  59. {notionary-0.1.27 → notionary-0.1.29}/notionary.egg-info/SOURCES.txt +0 -0
  60. {notionary-0.1.27 → notionary-0.1.29}/notionary.egg-info/dependency_links.txt +0 -0
  61. {notionary-0.1.27 → notionary-0.1.29}/notionary.egg-info/requires.txt +0 -0
  62. {notionary-0.1.27 → notionary-0.1.29}/notionary.egg-info/top_level.txt +0 -0
  63. {notionary-0.1.27 → notionary-0.1.29}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: notionary
3
- Version: 0.1.27
3
+ Version: 0.1.29
4
4
  Summary: A toolkit to convert between Markdown and Notion blocks
5
5
  Home-page: https://github.com/mathisarends/notionary
6
6
  Author: Mathis Arends
@@ -17,6 +17,8 @@ from notionary.util.logging_mixin import LoggingMixin
17
17
 
18
18
 
19
19
  class PageContentManager(LoggingMixin):
20
+ BATCH_SIZE = 100
21
+
20
22
  def __init__(
21
23
  self,
22
24
  page_id: str,
@@ -33,27 +35,40 @@ class PageContentManager(LoggingMixin):
33
35
  )
34
36
  self._chunker = NotionPageContentChunker()
35
37
 
36
- async def append_markdown(self, markdown_text: str) -> str:
38
+ async def append_markdown(self, markdown_text: str, append_divider = False) -> str:
37
39
  """
38
40
  Append markdown text to a Notion page, automatically handling content length limits.
39
- First strips out triple backtick markdown fences if they wrap the entire content.
40
41
 
41
42
  Args:
42
43
  markdown_text: The markdown text to append
43
44
  append_divider: If True, appends a divider after the markdown content (default: False)
44
45
  """
45
46
  try:
47
+ # Just the markdown synthax for the divider as it will be converted to a Notion divider block
48
+ if append_divider:
49
+ markdown_text = markdown_text + "\n\n---\n\n"
50
+
46
51
  blocks = self._markdown_to_notion_converter.convert(markdown_text)
47
52
  fixed_blocks = self._chunker.fix_blocks_content_length(blocks)
48
53
 
49
- result = await self._client.patch(
50
- f"blocks/{self.page_id}/children", {"children": fixed_blocks}
51
- )
52
- return (
53
- "Successfully added text to the page."
54
- if result
55
- else "Failed to add text."
56
- )
54
+ total_blocks = len(fixed_blocks)
55
+ num_batches = (total_blocks + self.BATCH_SIZE - 1) // self.BATCH_SIZE
56
+
57
+ all_success = True
58
+ for batch_num in range(num_batches):
59
+ start_idx = batch_num * self.BATCH_SIZE
60
+ end_idx = min((batch_num + 1) * self.BATCH_SIZE, total_blocks)
61
+ batch = fixed_blocks[start_idx:end_idx]
62
+
63
+ batch_success = await self._process_batch(batch, batch_num, num_batches)
64
+ if not batch_success:
65
+ all_success = False
66
+ break
67
+
68
+ if all_success:
69
+ return f"Successfully added {total_blocks} blocks to the page in {num_batches} batch(es)."
70
+ return "Failed to add all blocks. See logs for details."
71
+
57
72
  except Exception as e:
58
73
  self.logger.error("Error appending markdown: %s", str(e))
59
74
  raise
@@ -178,3 +193,19 @@ class PageContentManager(LoggingMixin):
178
193
  async def get_text(self) -> str:
179
194
  blocks = await self.get_page_blocks_with_children()
180
195
  return self._notion_to_markdown_converter.convert(blocks)
196
+
197
+
198
+ async def _process_batch(self, batch: List[Dict], batch_num: int, num_batches: int) -> bool:
199
+ """
200
+ Verarbeitet einen einzelnen Batch von Blöcken und gibt zurück, ob es erfolgreich war.
201
+ """
202
+ result = await self._client.patch(
203
+ f"blocks/{self.page_id}/children", {"children": batch}
204
+ )
205
+
206
+ if not result:
207
+ self.logger.error("Failed to add batch %d/%d to page.", batch_num + 1, num_batches)
208
+ return False
209
+
210
+ self.logger.info("Successfully added batch %d/%d (%d blocks) to page.", batch_num + 1, num_batches, len(batch))
211
+ return True
@@ -32,14 +32,14 @@ class NotionPageIconManager(LoggingMixin):
32
32
 
33
33
  if not page_data:
34
34
  return ""
35
-
35
+
36
36
  # Get icon data, default to empty dict if not present or None
37
37
  icon_data = page_data.get("icon")
38
-
38
+
39
39
  # If icon is None or not present, return None
40
40
  if not icon_data:
41
41
  return ""
42
-
42
+
43
43
  icon_type = icon_data.get("type")
44
44
 
45
45
  if icon_type == "emoji":
@@ -40,4 +40,14 @@ class NotionPageCoverManager(LoggingMixin):
40
40
  if not page_data:
41
41
  return ""
42
42
 
43
- return page_data.get("cover", {}).get("external", {}).get("url", "")
43
+ cover = page_data.get("cover")
44
+
45
+ if not cover or not isinstance(cover, dict):
46
+ return ""
47
+
48
+ external = cover.get("external")
49
+
50
+ if not external or not isinstance(external, dict):
51
+ return ""
52
+
53
+ return external.get("url", "")
@@ -130,7 +130,7 @@ class NotionPage(LoggingMixin):
130
130
  self._url_loaded = True
131
131
  return self._url
132
132
 
133
- async def append_markdown(self, markdown: str) -> str:
133
+ async def append_markdown(self, markdown: str, append_divider = False) -> str:
134
134
  """
135
135
  Append markdown content to the page.
136
136
 
@@ -140,7 +140,7 @@ class NotionPage(LoggingMixin):
140
140
  Returns:
141
141
  str: Status or confirmation message.
142
142
  """
143
- return await self._page_content_manager.append_markdown(markdown_text=markdown)
143
+ return await self._page_content_manager.append_markdown(markdown_text=markdown, append_divider=append_divider)
144
144
 
145
145
  async def clear(self) -> str:
146
146
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: notionary
3
- Version: 0.1.27
3
+ Version: 0.1.29
4
4
  Summary: A toolkit to convert between Markdown and Notion blocks
5
5
  Home-page: https://github.com/mathisarends/notionary
6
6
  Author: Mathis Arends
@@ -2,7 +2,7 @@ from setuptools import setup, find_namespace_packages
2
2
 
3
3
  setup(
4
4
  name="notionary",
5
- version="0.1.27",
5
+ version="0.1.29",
6
6
  packages=find_namespace_packages(include=["notionary*"]),
7
7
  install_requires=[
8
8
  "httpx>=0.28.0",
File without changes
File without changes
File without changes