Merge pull request #3 from oneeyedman/patch-1

Remove super weird invisible unicode spaces added by the Ivory client on MacOS :)
This commit is contained in:
Roboron3042 2023-06-13 22:48:55 +02:00 committed by GitHub
commit 0fedfb7c70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

View File

@ -1,3 +1,4 @@
import re
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from common import get_api from common import get_api
from common import list_append from common import list_append
@ -21,6 +22,8 @@ last_ids = list_read(bot_name)
max_notifications=10 max_notifications=10
new_last_ids=[] new_last_ids=[]
notifications = api.notifications(types=["mention"],limit=max_notifications) notifications = api.notifications(types=["mention"],limit=max_notifications)
no_unicode_spaces_pattern = r"[\u200B-\u200D\u202A\u202C\uFEFF]"
for n in notifications: for n in notifications:
new_last_ids.append(n['id']) new_last_ids.append(n['id'])
@ -30,7 +33,8 @@ for i in range(0, max_notifications - 5):
n = notifications[i] n = notifications[i]
if str(n['id']) not in last_ids: if str(n['id']) not in last_ids:
# Mentions data are HTML paragraphs so we delete everything between <> to clean it up # Mentions data are HTML paragraphs so we delete everything between <> to clean it up
content = BeautifulSoup(n['status']['content'], "html.parser").get_text().split(" ") rawContent = BeautifulSoup(n['status']['content'], "html.parser").get_text()
content = re.sub(no_unicode_spaces_pattern, "", rawContent).split(" ")
try: try:
first_mention = content[0] first_mention = content[0]
target = "@" + content[1] target = "@" + content[1]