From b80aa622f5235c2ca47f6be60051ea215e65e41d Mon Sep 17 00:00:00 2001 From: "Sam'an Herman-Griffiths (Innolitics)" Date: Thu, 14 Sep 2023 18:25:00 -0500 Subject: [PATCH] add database handle for emoji icon --- n2y/database.py | 13 ++++++++++++- n2y/page.py | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/n2y/database.py b/n2y/database.py index 44b886fa..313eb7f7 100644 --- a/n2y/database.py +++ b/n2y/database.py @@ -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 = { @@ -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": diff --git a/n2y/page.py b/n2y/page.py index adb25bc5..e72cdadd 100644 --- a/n2y/page.py +++ b/n2y/page.py @@ -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 = {