From 268bb80bfde50267c3ce52585e89fdd39840dd2d Mon Sep 17 00:00:00 2001 From: Stijn De Clercq Date: Wed, 3 Mar 2021 18:13:22 +0100 Subject: [PATCH] Add markdown support for ufora notifications, store notifications using IDs --- data/embeds/ufora.py | 21 ++++++++++++++++++++- functions/ufora_notifications.py | 5 +++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/data/embeds/ufora.py b/data/embeds/ufora.py index 9d1d13c..c02cbff 100644 --- a/data/embeds/ufora.py +++ b/data/embeds/ufora.py @@ -26,6 +26,9 @@ class UforaNotification: return embed + def get_id(self): + return int(self._notif_id) if self._notif_id is not None else self._content["id"] + def _create_url(self): if self._notif_id is None or self._course_id is None: return self._content["link"] @@ -52,11 +55,27 @@ class UforaNotification: def _clean_content(self, text: str): html_table = { + # CHARACTERS: "&": '&', """: '"', "apos;": "'", ">": ">", - "<": "<" + "<": "<", + # MARKDOWN SUPPORT: + "": "**", + "": "**", + "": "**", + "": "**", + "": "*", + "": "*", + "": "*", + "": "*", + "": "~~", + "": "~~", + "": "__", + "": "__", + # Represent paragraphs with newlines + "

": "\n" } # Unescape HTML diff --git a/functions/ufora_notifications.py b/functions/ufora_notifications.py index 11b9f53..ecb8a1c 100644 --- a/functions/ufora_notifications.py +++ b/functions/ufora_notifications.py @@ -41,9 +41,10 @@ def run(): if feed: for item in feed: - notifications[course].append(item["id"]) + notification = UforaNotification(item, course) + new_notifications.append(notification) - new_notifications.append(UforaNotification(item, course)) + notifications[course].append(notification.get_id()) # Update list of notifications if new_notifications: