notionary 0.1.15__py3-none-any.whl → 0.1.16__py3-none-any.whl

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.
@@ -88,26 +88,40 @@ class NotionRelationManager(LoggingMixin):
88
88
  ]
89
89
 
90
90
  async def get_relation_values(self, property_name: str) -> List[str]:
91
- """
92
- Returns the current relation values for a property.
91
+ """
92
+ Returns the titles of the pages linked via a relation property.
93
93
 
94
- Args:
95
- property_name: Name of the relation property
94
+ Args:
95
+ property_name: Name of the relation property
96
96
 
97
- Returns:
98
- List[str]: List of linked page IDs
99
- """
100
- properties = await self._get_page_properties()
97
+ Returns:
98
+ List[str]: List of linked page titles
99
+ """
100
+ properties = await self._get_page_properties()
101
101
 
102
- if property_name not in properties:
103
- return []
102
+ if property_name not in properties:
103
+ return []
104
104
 
105
- prop_data = properties[property_name]
105
+ prop_data = properties[property_name]
106
106
 
107
- if prop_data.get("type") != "relation" or "relation" not in prop_data:
108
- return []
107
+ if prop_data.get("type") != "relation" or "relation" not in prop_data:
108
+ return []
109
+
110
+ resolver = NotionPageTitleResolver(self._client)
111
+ titles = []
109
112
 
110
- return [rel.get("id") for rel in prop_data["relation"]]
113
+ for rel in prop_data["relation"]:
114
+ page_id = rel.get("id")
115
+ if not page_id:
116
+ continue
117
+
118
+ title = await resolver.get_title_by_page_id(page_id)
119
+ if not title:
120
+ continue
121
+
122
+ titles.append(title)
123
+
124
+ return titles
111
125
 
112
126
  async def get_relation_details(
113
127
  self, property_name: str
@@ -373,6 +387,7 @@ class NotionRelationManager(LoggingMixin):
373
387
  async def get_all_relations(self) -> Dict[str, List[str]]:
374
388
  """Returns all relation properties and their values."""
375
389
  relation_properties = await self.get_relation_property_ids()
390
+
376
391
  if not relation_properties:
377
392
  return {}
378
393
 
@@ -19,25 +19,69 @@ class NotionPageTitleResolver(LoggingMixin):
19
19
 
20
20
  for result in search_results.get("results", []):
21
21
  properties = result.get("properties", {})
22
+ if not properties:
23
+ continue
22
24
 
23
25
  for prop_value in properties.values():
24
- if prop_value.get("type") == "title":
25
- title_texts = prop_value.get("title", [])
26
+ if prop_value.get("type") != "title":
27
+ continue
26
28
 
27
- page_title = " ".join(
28
- [t.get("plain_text", "") for t in title_texts]
29
- )
29
+ title_texts = prop_value.get("title", [])
30
+ if not title_texts:
31
+ continue
32
+
33
+ page_title = " ".join(
34
+ [t.get("plain_text", "") for t in title_texts]
35
+ )
30
36
 
31
- if page_title == title or title in page_title:
32
- self.logger.debug(
33
- "Found page: '%s' with ID: %s",
34
- page_title,
35
- result.get("id"),
36
- )
37
- return result.get("id")
37
+ if not page_title:
38
+ continue
39
+
40
+ if page_title == title or title in page_title:
41
+ self.logger.debug(
42
+ "Found page: '%s' with ID: %s",
43
+ page_title,
44
+ result.get("id"),
45
+ )
46
+ return result.get("id")
38
47
 
39
48
  self.logger.debug("No page found with title '%s'", title)
40
49
  return None
50
+
41
51
  except Exception as e:
42
52
  self.logger.error("Error while searching for page '%s': %s", title, e)
43
53
  return None
54
+
55
+
56
+ async def get_title_by_page_id(self, page_id: str) -> Optional[str]:
57
+ """
58
+ Retrieves the title of a Notion page by its page ID.
59
+
60
+ Args:
61
+ page_id: The ID of the Notion page.
62
+
63
+ Returns:
64
+ The title of the page, or None if not found.
65
+ """
66
+ try:
67
+ page = await self._client.get(f"pages/{page_id}")
68
+ properties = page.get("properties", {})
69
+
70
+ for prop in properties.values():
71
+ if prop.get("type") != "title":
72
+ continue
73
+
74
+ title_parts = prop.get("title", [])
75
+ if not title_parts:
76
+ continue
77
+
78
+ title = " ".join([t.get("plain_text", "") for t in title_parts])
79
+ if title:
80
+ return title
81
+
82
+ self.logger.debug("No title found for page ID '%s'", page_id)
83
+ return None
84
+
85
+ except Exception as e:
86
+ self.logger.error("Error retrieving title for page ID '%s': %s", page_id, e)
87
+ return None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: notionary
3
- Version: 0.1.15
3
+ Version: 0.1.16
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
@@ -42,15 +42,15 @@ notionary/page/properites/page_property_manager.py,sha256=Xl8Cwn8WVszqpFXT_NvASk
42
42
  notionary/page/properites/property_formatter.py,sha256=d_Nr5XQxgjB6VIS0u3ey14MOUKY416o_BvdXjbkUNAQ,3667
43
43
  notionary/page/properites/property_operation_result.py,sha256=PhxHJJxxG2BdDl7aswhWnMSmf9RQtoinKkRHDoqxwCs,3913
44
44
  notionary/page/properites/property_value_extractor.py,sha256=1BfyCYrFzfIUmNTozavrLTjG--6P6Dy2tkewf6rHHwQ,2353
45
- notionary/page/relations/notion_page_relation_manager.py,sha256=D7JZJLXjX2Jn3CIseJxoMK9qL9gp88t4NmL9Ihu06eg,12682
46
- notionary/page/relations/notion_page_title_resolver.py,sha256=jUYsEkfyDgdh77oh2awYEB5g1vQqLBq6xYSXL-4uPH8,1722
45
+ notionary/page/relations/notion_page_relation_manager.py,sha256=xyV92IFjFbizqDLV9UK89JVyDAtxBLZqVDId-orRP0A,13128
46
+ notionary/page/relations/notion_page_title_resolver.py,sha256=1751DKRI0o586-78fRDWEtfWyQViMir_08v7YpetxfY,3016
47
47
  notionary/page/relations/page_database_relation.py,sha256=F9aGXFjjL8ZLNbfTGeGm_QAyXhz2AEOw7GgDLdprEcE,2313
48
48
  notionary/page/relations/relation_operation_result.py,sha256=NDxBzGntOxc_89ti-HG8xDSqfY6PwyGHKHrrKbCzNjM,5010
49
49
  notionary/util/logging_mixin.py,sha256=fKsx9t90bwvL74ZX3dU-sXdC4TZCQyO6qU9I8txkw_U,1369
50
50
  notionary/util/page_id_utils.py,sha256=EYNMxgf-7ghzL5K8lKZBZfW7g5CsdY0Xuj4IYmU8RPk,1381
51
51
  notionary/util/singleton_decorator.py,sha256=GTNMfIlVNRUVMw_c88xqd12-DcqZJjmyidN54yqiNVw,472
52
- notionary-0.1.15.dist-info/licenses/LICENSE,sha256=zOm3cRT1qD49eg7vgw95MI79rpUAZa1kRBFwL2FkAr8,1120
53
- notionary-0.1.15.dist-info/METADATA,sha256=uXefq6BdsjQnMAf34az8oWfMb2_6L068evq_G8UGWlE,6154
54
- notionary-0.1.15.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
55
- notionary-0.1.15.dist-info/top_level.txt,sha256=fhONa6BMHQXqthx5PanWGbPL0b8rdFqhrJKVLf_adSs,10
56
- notionary-0.1.15.dist-info/RECORD,,
52
+ notionary-0.1.16.dist-info/licenses/LICENSE,sha256=zOm3cRT1qD49eg7vgw95MI79rpUAZa1kRBFwL2FkAr8,1120
53
+ notionary-0.1.16.dist-info/METADATA,sha256=tKeWZjbUCsadM9l0ocHVCfPwzdQxZQwhqgz9KLZJHQI,6154
54
+ notionary-0.1.16.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
55
+ notionary-0.1.16.dist-info/top_level.txt,sha256=fhONa6BMHQXqthx5PanWGbPL0b8rdFqhrJKVLf_adSs,10
56
+ notionary-0.1.16.dist-info/RECORD,,