Skip to content

Commit

Permalink
fix: fix emoji icon parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
vzhd1701 committed Jul 21, 2022
1 parent 2da0883 commit 01f613e
Show file tree
Hide file tree
Showing 4 changed files with 848 additions and 3 deletions.
22 changes: 19 additions & 3 deletions csv2notion/notion_convert_map.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from datetime import datetime
from pathlib import Path
from typing import Union
from typing import Optional, Union

from dateutil.parser import ParserError
from dateutil.parser import parse as date_parse
from emoji import is_emoji # type: ignore
from emoji import distinct_emoji_list, emoji_count, replace_emoji # type: ignore

from csv2notion.notion_type_guess import is_url
from csv2notion.utils_exceptions import TypeConversionError
Expand Down Expand Up @@ -35,8 +35,24 @@ def map_number(s: str) -> Union[int, float]:


def map_icon(s: str) -> FileType:
return s if is_url(s) or is_emoji(s) else Path(s)
icon_emoji = _get_icon_emoji(s)
if icon_emoji:
return icon_emoji

return s if is_url(s) else Path(s)


def map_url_or_file(s: str) -> FileType:
return s if is_url(s) else Path(s)


def _get_icon_emoji(s: str) -> Optional[str]:
# string has anything other than emoji
if replace_emoji(s) != "":
return None

# string must contain exactly one emoji for icon
if emoji_count(s) != 1:
return None

return str(distinct_emoji_list(s)[0])
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["6c03ea0c-e9a4-48b7-9d70-41b7e998ad00", "9be604bb-887f-42b4-b8f5-bccaf28d0666", "9f436ab6-cfb6-4272-aab3-3b2402db6a81", "6b70a4ec-1231-4936-a783-b02e5ecead2b"]
Loading

0 comments on commit 01f613e

Please sign in to comment.