diff --git a/data/embeds/ufora.py b/data/embeds/ufora.py
index df52c83..3a38c46 100644
--- a/data/embeds/ufora.py
+++ b/data/embeds/ufora.py
@@ -1,15 +1,16 @@
from datetime import datetime, timedelta
from discord import Embed, Colour
+from functions.stringFormatters import leadingZero as lz
from functions.timeFormatters import intToWeekday
import pytz
import re
class UforaNotification:
- def __init__(self, content: dict, course):
+ def __init__(self, content: dict, course, notif_id, course_id):
self._content: dict = content
self._course = course
- self._notif_id, self._course_id = self._find_ids(self._content["id"])
+ self._notif_id, self._course_id = notif_id, course_id
self._view_url = self._create_url()
self._title = self._clean_content(self._content["title"])
self._description = self._get_description()
@@ -35,16 +36,6 @@ class UforaNotification:
return "https://ufora.ugent.be/d2l/le/news/{0}/{1}/view?ou={0}".format(self._course_id, self._notif_id)
- def _find_ids(self, url: str):
- match = re.search(r"[0-9]+-[0-9]+$", url)
-
- if not match:
- return None, None
-
- spl = match[0].split("-")
-
- return spl[0], spl[1]
-
def _get_description(self):
desc = self._clean_content(self._content["summary"])
@@ -76,7 +67,10 @@ class UforaNotification:
"": "__",
"": "__",
# Represent paragraphs with newlines
- "
": "\n"
+ "": "\n",
+ "
": "\n",
+ "
": "\n",
+ "
": "\n"
}
# Unescape HTML
@@ -96,6 +90,6 @@ class UforaNotification:
return "{} {}/{}/{} om {}:{}:{}".format(
intToWeekday(dt.weekday()),
- dt.day, dt.month, dt.year,
- dt.hour, dt.minute, dt.second
+ lz(dt.day), lz(dt.month), lz(dt.year),
+ lz(dt.hour), lz(dt.minute), lz(dt.second)
)
diff --git a/functions/ufora_notifications.py b/functions/ufora_notifications.py
index ecb8a1c..26a5419 100644
--- a/functions/ufora_notifications.py
+++ b/functions/ufora_notifications.py
@@ -1,3 +1,5 @@
+import re
+
import feedparser
from data.embeds import UforaNotification
import json
@@ -37,14 +39,14 @@ def run():
feed = feedparser.parse(url)
# Filter out old notifications
- feed = list(filter(lambda f: f["id"] not in notifications[course], feed.entries))
+ feed = list(filter(lambda f: _parse_ids(f["id"])[0] not in notifications[course], feed.entries))
if feed:
for item in feed:
- notification = UforaNotification(item, course)
- new_notifications.append(notification)
+ notif_id, course_id = _parse_ids(item["id"])
+ new_notifications.append(UforaNotification(item, course, notif_id, course_id))
- notifications[course].append(notification.get_id())
+ notifications[course].append(notif_id)
# Update list of notifications
if new_notifications:
@@ -52,3 +54,14 @@ def run():
json.dump(notifications, fp)
return new_notifications
+
+
+def _parse_ids(url: str):
+ match = re.search(r"[0-9]+-[0-9]+$", url)
+
+ if not match:
+ return None, None
+
+ spl = match[0].split("-")
+
+ return spl[0], spl[1]