Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add database handle for emoji icon #152

Merged
merged 1 commit into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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