Merge pull request #91 from stijndcl/schedules_minors

Schedules minors, update Ufora id's
pull/93/head
Stijn De Clercq 2021-09-20 19:09:35 +02:00 committed by GitHub
commit 298a1e13d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 315 additions and 101 deletions

View File

@ -42,9 +42,9 @@ class School(commands.Cog):
embed.set_footer(text="Omwille van de coronamaatregelen is er een beperkter aanbod, en kan je enkel nog eten afhalen. Ter plaatse eten is niet meer mogelijk.") embed.set_footer(text="Omwille van de coronamaatregelen is er een beperkter aanbod, en kan je enkel nog eten afhalen. Ter plaatse eten is niet meer mogelijk.")
await ctx.send(embed=embed) await ctx.send(embed=embed)
# @commands.command(name="Les", aliases=["Class", "Classes", "Sched", "Schedule"], usage="[Dag]*") @commands.command(name="Les", aliases=["Class", "Classes", "Sched", "Schedule"], usage="[Dag]*")
# @commands.check(checks.allowedChannels) # @commands.check(checks.allowedChannels)
# @help.Category(category=Category.School) @help.Category(category=Category.School)
async def les(self, ctx, day=None): async def les(self, ctx, day=None):
date = les.find_target_date(day) date = les.find_target_date(day)

View File

@ -143,6 +143,7 @@ class Schedule:
self.schedule_dict: Dict = self.load_schedule_file() self.schedule_dict: Dict = self.load_schedule_file()
self.start_date = fromArray(self.schedule_dict["semester_start"]) self.start_date = fromArray(self.schedule_dict["semester_start"])
self.end_date = fromArray(self.schedule_dict["semester_end"]) self.end_date = fromArray(self.schedule_dict["semester_end"])
self._forward_to_semester()
# Semester is over # Semester is over
if self.end_date < self.day: if self.end_date < self.day:
@ -167,6 +168,14 @@ class Schedule:
self.weekday_str = intToWeekday(self.day.weekday()) self.weekday_str = intToWeekday(self.day.weekday())
def _forward_to_semester(self):
"""
In case the semester hasn't started yet, fast forward the current date
by a week until it's no longer necessary
"""
while self.day < self.start_date:
self.day += timedelta(weeks=1)
def check_holidays(self): def check_holidays(self):
""" """
Do all holiday-related stuff here to avoid multiple loops Do all holiday-related stuff here to avoid multiple loops
@ -234,6 +243,22 @@ class Schedule:
return HolidayEmbed(self) return HolidayEmbed(self)
slots: List[List[Timeslot]] = [self.find_slots_for_course(course) for course in self.schedule_dict["schedule"]] slots: List[List[Timeslot]] = [self.find_slots_for_course(course) for course in self.schedule_dict["schedule"]]
minor_slots = {}
# Find minor slots
for minor in self.schedule_dict["minors"]:
m_slots = []
for course in minor["schedule"]:
# Go over every course
m_slots.append(self.find_slots_for_course(course))
# Flatten list
m_slots = [item for sublist in m_slots for item in sublist]
# Sort by timestamp
m_slots.sort(key=lambda x: x.start_time)
minor_slots[minor["name"]] = m_slots
slots_flattened = [item for sublist in slots for item in sublist] slots_flattened = [item for sublist in slots for item in sublist]
# Sort by timestamp # Sort by timestamp
@ -244,7 +269,7 @@ class Schedule:
if not not_canceled: if not not_canceled:
return NoClassEmbed(self, slots_flattened) return NoClassEmbed(self, slots_flattened)
return ScheduleEmbed(self, slots_flattened, not_canceled) return ScheduleEmbed(self, slots_flattened, not_canceled, minor_slots)
@dataclass @dataclass
@ -270,6 +295,9 @@ class LesEmbed(ABC):
def get_extras(self) -> str: def get_extras(self) -> str:
return "" return ""
def add_minors(self, embed: Embed):
pass
def get_online_links(self) -> str: def get_online_links(self) -> str:
return "" return ""
@ -289,6 +317,8 @@ class LesEmbed(ABC):
if links: if links:
embed.add_field(name="Online links", value=links, inline=False) embed.add_field(name="Online links", value=links, inline=False)
self.add_minors(embed)
# Add extras if there are any # Add extras if there are any
extras = self.get_extras() extras = self.get_extras()
if extras: if extras:
@ -332,10 +362,27 @@ class ScheduleEmbed(LesEmbed):
""" """
slots: List[Timeslot] slots: List[Timeslot]
slots_not_canceled: List[Timeslot] slots_not_canceled: List[Timeslot]
minor_slots: Dict[str, List[Timeslot]]
def get_description(self) -> str: def get_description(self) -> str:
return "\n".join(list(f"{entry}" for entry in self.slots_not_canceled)) return "\n".join(list(f"{entry}" for entry in self.slots_not_canceled))
def add_minors(self, embed: Embed):
for minor, slots in self.minor_slots.items():
if not slots:
continue
not_canceled = list(filter(lambda x: not x.canceled, slots))
info = "\n".join(list(str(entry) for entry in not_canceled))
special = list(filter(lambda x: x.is_special or x.canceled, slots))
# Add extra info about this minor
if special:
info += "\n" + "\n".join(list(entry.get_special_fmt_str() for entry in special))
embed.add_field(name=f"Minor {minor}", value=info, inline=False)
def get_extras(self) -> str: def get_extras(self) -> str:
special = list(filter(lambda x: x.is_special or x.canceled, self.slots)) special = list(filter(lambda x: x.is_special or x.canceled, self.slots))

View File

@ -1,58 +1,44 @@
{ {
"semester_start": [1, 7, 2021], "semester_start": [27, 9, 2021],
"semester_end": [1, 8, 2021], "semester_end": [23, 12, 2021],
"holidays": [ "holidays": [
{ {
"start_date": [2, 7, 2021, 23, 59, 59], "start_date": [1, 11, 2021, 0, 0, 0],
"end_date": [10, 8, 2021, 23, 59, 59] "end_date": [2, 11, 2021, 23, 59, 59]
},
{
"start_date": [11, 11, 2021, 0, 0, 0],
"end_date": [11, 11, 2021, 23, 59, 59]
} }
], ],
"minors": [
{
"name": "Beveiliging en parallelle systemen",
"online_links": {
"zoom": "https://ufora.ugent.be/d2l/ext/rp/439235/lti/framedlaunch/556e197e-e87b-4c27-be5d-53adc7a41826"
},
"schedule": [ "schedule": [
{ {
"course": "Computerarchitectuur", "course": "Modelleren en Simuleren",
"online_links": {
"zoom": "https://ufora.ugent.be/d2l/ext/rp/228912/lti/framedlaunch/556e197e-e87b-4c27-be5d-53adc7a41826",
"msteams": "https://teams.microsoft.com/l/team/19%3ad7295f0bc4634a61b461504d4a7134b3%40thread.tacv2/conversations?groupId=8755cb96-1ef5-4ea3-b806-eeebf8a85ae8&tenantId=d7811cde-ecef-496c-8f91-a1786241b99c"
},
"slots": [
]
},
{
"course": "Multimedia",
"online_links": {
"zoom": "https://ugent-be.zoom.us/j/94248831947?pwd=ZCt4UnBLSzViZnFEQmkzWE5SYnF2QT09"
},
"slots": [ "slots": [
{
"location": {
"campus": "Sterre",
"building": "S12",
"room": "0.1"
},
"time": {
"day": "maandag",
"start": 1000,
"end": 1300
}
},
{ {
"location": { "location": {
"campus": "Sterre", "campus": "Sterre",
"building": "S9", "building": "S9",
"room": "A3" "room": "3.1 Konrad Zuse"
}, },
"time": {
"day": "woensdag",
"start": 1130,
"end": 1330
}
},
{
"online": "zoom",
"time": {
"day": "vrijdag",
"start": 1300,
"end": 1530
}
}
]
},
{
"course": "Wetenschappelijk Rekenen",
"online_links": {
"zoom": "https://ufora.ugent.be/d2l/ext/rp/236404/lti/framedlaunch/556e197e-e87b-4c27-be5d-53adc7a41826"
},
"slots": [
{
"online": "zoom",
"time": { "time": {
"day": "dinsdag", "day": "dinsdag",
"start": 1130, "start": 1130,
@ -60,40 +46,43 @@
} }
}, },
{ {
"online": "zoom", "location": {
"time": { "campus": "Sterre",
"day": "woensdag", "building": "S9",
"start": 1500, "room": "3.1 Konrad Zuse"
"end": 1800
}
}, },
{
"online": "zoom",
"time": { "time": {
"day": "donderdag", "day": "donderdag",
"start": 830, "start": 1430,
"end": 1000 "end": 1600
} }
} }
] ]
}, },
{ {
"course": "Software Engineering Lab 1", "course": "Parallelle Computersystemen",
"online_links": { "online_links": {
"zoom": "https://ufora.ugent.be/d2l/ext/rp/235800/lti/framedlaunch/556e197e-e87b-4c27-be5d-53adc7a41826", "zoom": "https://ufora.ugent.be/d2l/ext/rp/449671/lti/framedlaunch/556e197e-e87b-4c27-be5d-53adc7a41826"
"msteams": "https://teams.microsoft.com/l/team/19%3a4dfd5b2fb1ae4aa9b72706aa3a0d6867%40thread.tacv2/conversations?groupId=256d5c58-5d53-43f5-9436-497b0c852c75&tenantId=d7811cde-ecef-496c-8f91-a1786241b99c"
}, },
"slots": [ "slots": [
{ {
"online": "msteams", "location": {
"campus": "Ardoyen",
"building": "iGent 126",
"room": "Auditorium 1"
},
"time": { "time": {
"day": "dinsdag", "day": "woensdag",
"start": 1430, "start": 1430,
"end": 1700 "end": 1730
} }
}, },
{ {
"online": "msteams", "location": {
"campus": "Ardoyen",
"building": "iGent 126",
"room": "Auditorium 1"
},
"time": { "time": {
"day": "vrijdag", "day": "vrijdag",
"start": 830, "start": 830,
@ -101,37 +90,207 @@
} }
} }
] ]
}
]
}, },
{ {
"course": "Webdevelopment", "name": "Elektrotechniek en Telecommunicatie",
"online_links": { "schedule": [
"zoom": "https://ugent-be.zoom.us/j/93166767783?pwd=MWdvb1BnNnlPSnAyNk52QmRzdjcwdz09" {
}, "course": "Inleiding tot Telecommunicatie",
"slots": [ "slots": [
{ {
"weeks": { "location": {
"6": { "campus": "Ardoyen",
"canceled": true "building": "iGent 125",
"room": "Systems"
},
"time": {
"day": "maandag",
"start": 1000,
"end": 1300
} }
}, },
{
"location": {
"campus": "Ardoyen",
"building": "iGent 125",
"room": "Systems"
},
"time": {
"day": "dinsdag",
"start": 1300,
"end": 1600
}
}
]
},
{
"course": "Wiskundige Modellering",
"slots": [
{
"location": { "location": {
"campus": "Sterre", "campus": "Sterre",
"building": "S9", "building": "S9",
"room": "A3" "room": "1.1"
}, },
"time": { "time": {
"day": "woensdag", "day": "maandag",
"start": 900, "start": 830,
"end": 1100 "end": 1000
} }
}, },
{ {
"online": "zoom", "location": {
"campus": "Sterre",
"building": "S8",
"room": "3.2"
},
"time": { "time": {
"day": "donderdag", "day": "donderdag",
"start": 1430,
"end": 1600
}
},
{
"location": {
"campus": "Sterre",
"building": "S8",
"room": "3.2"
},
"time": {
"day": "vrijdag",
"start": 830,
"end": 1130
}
}
]
}
]
},
{
"name": "Onderwijs",
"schedule": []
}
],
"schedule": [
{
"course": "Algoritmen en Datastructuren 3",
"online_links": {
"zoom": "https://ufora.ugent.be/d2l/ext/rp/437923/lti/framedlaunch/556e197e-e87b-4c27-be5d-53adc7a41826"
},
"slots": [
{
"location": {
"campus": "Sterre",
"building": "S9",
"room": "3.1 Konrad Zuse"
},
"time": {
"day": "dinsdag",
"start": 830,
"end": 1000
}
},
{
"location": {
"campus": "Sterre",
"building": "S9",
"room": "1.1 Alan Turing"
},
"time": {
"day": "dinsdag",
"start": 1000, "start": 1000,
"end": 1130
}
},
{
"location": {
"campus": "Sterre",
"building": "S9",
"room": "1.1 Alan Turing"
},
"time": {
"day": "woensdag",
"start": 830,
"end": 1130
}
}
]
},
{
"course": "Artificiële Intelligentie",
"online_links": {
"zoom": "https://ufora.ugent.be/d2l/ext/rp/439739/lti/framedlaunch/556e197e-e87b-4c27-be5d-53adc7a41826"
},
"slots": [
{
"location": {
"campus": "Sterre",
"building": "S8",
"room": "0.1"
},
"time": {
"day": "maandag",
"start": 1430,
"end": 1730
}
},
{
"location": {
"campus": "Sterre",
"building": "S9",
"room": "1.1 Alan Turing"
},
"time": {
"day": "woensdag",
"start": 1130,
"end": 1300 "end": 1300
} }
},
{
"location": {
"campus": "Sterre",
"building": "S9",
"room": "3.1 Konrad Zuse"
},
"time": {
"day": "donderdag",
"start": 1300,
"end": 1430
}
}
]
},
{
"course": "Besturingssystemen",
"online_links": {
"zoom": "https://ufora.ugent.be/d2l/ext/rp/442814/lti/framedlaunch/556e197e-e87b-4c27-be5d-53adc7a41826"
},
"slots": [
{
"location": {
"campus": "Ardoyen",
"building": "iGent 126",
"room": "Auditorium 1"
},
"time": {
"day": "donderdag",
"start": 830,
"end": 1130
}
},
{
"location": {
"campus": "Ardoyen",
"building": "iGent 126",
"room": "Auditorium 1"
},
"time": {
"day": "vrijdag",
"start": 1300,
"end": 1600
}
} }
] ]
} }

View File

@ -1,21 +1,28 @@
import re import re
import feedparser
from data.embeds import UforaNotification from data.embeds import UforaNotification
import feedparser
import json import json
from settings import UFORA_TOKEN
course_urls = { course_urls = {
"Algoritmen en Datastructuren 2": "https://ufora.ugent.be/d2l/le/news/rss/222018/course?token=aehhv6utkf46t8cc102e0&ou=222018", "Algoritmen en Datastructuren 3": "https://ufora.ugent.be/d2l/le/news/rss/437923/course?token=",
"Communicatienetwerken": "https://ufora.ugent.be/d2l/le/news/rss/221184/course?token=aehhv6utkf46t8cc102e0&ou=221184", "Artificiële Intelligentie": "https://ufora.ugent.be/d2l/le/news/rss/439739/course?token=",
"Computerarchitectuur": "https://ufora.ugent.be/d2l/le/news/rss/228912/course?token=aehhv6utkf46t8cc102e0&ou=228912", "Automaten, Berekenbaarheid en Complexiteit": "https://ufora.ugent.be/d2l/le/news/rss/439079/course?token=",
"Functioneel Programmeren": "https://ufora.ugent.be/d2l/le/news/rss/236396/course?token=aehhv6utkf46t8cc102e0&ou=236396", "Besturingssystemen": "https://ufora.ugent.be/d2l/le/news/rss/442814/course?token=",
"Multimedia": "https://ufora.ugent.be/d2l/le/news/rss/236949/course?token=aehhv6utkf46t8cc102e0&ou=236949", "Communicatienetwerken": "https://ufora.ugent.be/d2l/le/news/rss/447014/course?token=",
"Software Engineering Lab 1": "https://ufora.ugent.be/d2l/le/news/rss/235800/course?token=aehhv6utkf46t8cc102e0&ou=235800", "Computationele Biologie": "https://ufora.ugent.be/d2l/le/news/rss/448904/course?token=",
"Statistiek en Probabiliteit": "https://ufora.ugent.be/d2l/le/news/rss/236398/course?token=aehhv6utkf46t8cc102e0&ou=236398", "Computerarchitectuur": "https://ufora.ugent.be/d2l/le/news/rss/439172/course?token=",
"Systeemprogrammeren": "https://ufora.ugent.be/d2l/le/news/rss/222035/course?token=aehhv6utkf46t8cc102e0&ou=222035", "Informatiebeveiliging": "https://ufora.ugent.be/d2l/le/news/rss/444476/course?token=",
"Webdevelopment": "https://ufora.ugent.be/d2l/le/news/rss/223449/course?token=aehhv6utkf46t8cc102e0&ou=223449", "Inleiding tot Telecommunicatie": "https://ufora.ugent.be/d2l/le/news/rss/450232/course?token=",
"Wetenschappelijk Rekenen": "https://ufora.ugent.be/d2l/le/news/rss/236404/course?token=aehhv6utkf46t8cc102e0&ou=236404" "Logisch Programmeren": "https://ufora.ugent.be/d2l/le/news/rss/443368/course?token=",
"Modelleren en Simuleren": "https://ufora.ugent.be/d2l/le/news/rss/439235/course?token=",
"Parallelle Computersystemen": "https://ufora.ugent.be/d2l/le/news/rss/449671/course?token=",
"Software Engineering Lab 2": "https://ufora.ugent.be/d2l/le/news/rss/445170/course?token=",
"Statistiek en Probabiliteit": "https://ufora.ugent.be/d2l/le/news/rss/445169/course?token=",
"Wetenschappelijk Rekenen": "https://ufora.ugent.be/d2l/le/news/rss/445174/course?token=",
"Wiskundige Modellering": "https://ufora.ugent.be/d2l/le/news/rss/446530/course?token="
} }
@ -36,7 +43,7 @@ def run():
notifications[course] = [] notifications[course] = []
# Get the updated feed # Get the updated feed
feed = feedparser.parse(url) feed = feedparser.parse(f"url{UFORA_TOKEN}")
# Filter out old notifications # Filter out old notifications
feed = list(filter(lambda f: _parse_ids(f["id"])[0] not in notifications[course], feed.entries)) feed = list(filter(lambda f: _parse_ids(f["id"])[0] not in notifications[course], feed.entries))

View File

@ -21,6 +21,7 @@ SANDBOX = _to_bool(os.getenv("SANDBOX", "true"))
URBANDICTIONARY = os.getenv("URBANDICTIONARY", "") URBANDICTIONARY = os.getenv("URBANDICTIONARY", "")
IMGFLIP_NAME = os.getenv("IMGFLIPNAME", "") IMGFLIP_NAME = os.getenv("IMGFLIPNAME", "")
IMGFLIP_PASSWORD = os.getenv("IMGFLIPPASSWORD", "") IMGFLIP_PASSWORD = os.getenv("IMGFLIPPASSWORD", "")
UFORA_TOKEN = os.getenv("UFORA_TOKEN", "")
# Database credentials # Database credentials
DB_USERNAME = os.getenv("DBUSERNAME", "") DB_USERNAME = os.getenv("DBUSERNAME", "")