mirror of
https://github.com/stijndcl/didier.git
synced 2026-04-07 15:48:29 +02:00
Add support for linebreaks, parse id's beforehand to check properly, add leading zeroes to timestamp
This commit is contained in:
parent
1372f0a996
commit
db0e7b8f9b
2 changed files with 26 additions and 19 deletions
|
|
@ -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]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue