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

fix: decode unicode escape sequences (fixes emojis, Chinese, etc) #6

Merged
merged 3 commits into from
Nov 1, 2024
Merged
Changes from 1 commit
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
21 changes: 20 additions & 1 deletion aw_notify/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,25 @@ def checkin(testing=False):
send_checkin()


def decode_unicode_escapes(s: str):
"""
Decodes any Unicode escape sequences present in the input string
and returns the decoded result.

Args:
s (str): The input string which may contain Unicode escape sequences.

Returns:
str: The decoded string where Unicode escape sequences have been converted
to their corresponding characters.

Example:
Input: "\\u5de5\\u4f5c"
Output: "工作"
"""
return s.encode('utf-8').decode('unicode_escape')
ErikBjare marked this conversation as resolved.
Show resolved Hide resolved


def send_checkin(title="Time today", date=None):
"""
Sends a summary notification of the day.
Expand All @@ -346,7 +365,7 @@ def send_checkin(title="Time today", date=None):
][:4]

msg = ""
msg += "\n".join(f"- {c}: {t}" for c, t in top_categories)
msg += "\n".join(f"- {decode_unicode_escapes(c)}: {t}" for c, t in top_categories)
if msg:
notify(title, msg)
else:
Expand Down
Loading