Skip to content

Commit

Permalink
add database handle for emoji icon (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
sHermanGriffiths authored Sep 14, 2023
1 parent 9f45bfa commit 41b86ba
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion n2y/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def __init__(self, client, notion_data):
self.last_edited_time = fromisoformat(notion_data['last_edited_time'])
self.last_edited_by = client.wrap_notion_user(notion_data['last_edited_by'])
self.title = client.wrap_notion_rich_text_array(notion_data['title'])
self.icon = notion_data['icon'] and client.wrap_notion_file(notion_data['icon'])
self.icon = self._init_icon(notion_data['icon'])
self.cover = notion_data['cover'] and client.wrap_notion_file(notion_data['cover'])
self.archived = notion_data['archived']
self.schema = {
Expand Down Expand Up @@ -63,6 +63,17 @@ def _tuplize(self, item):
else:
return (item)

def _init_icon(self, icon_notion_data):
"""
The icon property is unique in that it can be either an emoji or a file.
"""
if icon_notion_data is None:
return None
elif icon_notion_data["type"] == "emoji":
return self.client.wrap_notion_emoji(icon_notion_data)
else:
return self.client.wrap_notion_file(icon_notion_data)

@property
def parent(self):
if self.notion_parent["type"] == "workspace":
Expand Down
2 changes: 1 addition & 1 deletion n2y/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __init__(self, client, notion_data):
self.last_edited_time = fromisoformat(notion_data['last_edited_time'])
self.last_edited_by = client.wrap_notion_user(notion_data['last_edited_by'])
self.archived = notion_data['archived']
self.emoji = self._init_icon(notion_data['icon'])
self.icon = self._init_icon(notion_data['icon'])
self.cover = notion_data['cover'] and client.wrap_notion_file(notion_data['cover'])
self.archived = notion_data['archived']
self.properties = {
Expand Down

0 comments on commit 41b86ba

Please sign in to comment.