Add markdown support for ufora notifications, store notifications using IDs

pull/42/head
Stijn De Clercq 2021-03-03 18:13:22 +01:00
parent c9bef3b300
commit 268bb80bfd
2 changed files with 23 additions and 3 deletions

View File

@ -26,6 +26,9 @@ class UforaNotification:
return embed 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): def _create_url(self):
if self._notif_id is None or self._course_id is None: if self._notif_id is None or self._course_id is None:
return self._content["link"] return self._content["link"]
@ -52,11 +55,27 @@ class UforaNotification:
def _clean_content(self, text: str): def _clean_content(self, text: str):
html_table = { html_table = {
# CHARACTERS:
"&": '&', "&": '&',
""": '"', """: '"',
"apos;": "'", "apos;": "'",
">": ">", ">": ">",
"&lt;": "<" "&lt;": "<",
# MARKDOWN SUPPORT:
"<b>": "**",
"</b>": "**",
"<strong>": "**",
"</strong>": "**",
"<i>": "*",
"</i>": "*",
"<em>": "*",
"</em>": "*",
"<del>": "~~",
"</del>": "~~",
"<ins>": "__",
"</ins>": "__",
# Represent paragraphs with newlines
"</p>": "\n"
} }
# Unescape HTML # Unescape HTML

View File

@ -41,9 +41,10 @@ def run():
if feed: if feed:
for item in 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 # Update list of notifications
if new_notifications: if new_notifications: