mirror of https://github.com/stijndcl/didier
Parse minors
parent
a48f15d464
commit
43bce8d8fb
|
@ -124,7 +124,6 @@ class Timeslot:
|
||||||
is_special=special, location=location, online_platform=online_platform, online_link=online_link)
|
is_special=special, location=location, online_platform=online_platform, online_link=online_link)
|
||||||
|
|
||||||
|
|
||||||
# TODO parse minors
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Schedule:
|
class Schedule:
|
||||||
day: datetime
|
day: datetime
|
||||||
|
@ -244,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
|
||||||
|
@ -254,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
|
||||||
|
@ -280,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 ""
|
||||||
|
|
||||||
|
@ -299,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:
|
||||||
|
@ -342,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))
|
||||||
|
|
||||||
|
|
|
@ -97,7 +97,7 @@
|
||||||
"name": "Elektrotechniek en Telecommunicatie",
|
"name": "Elektrotechniek en Telecommunicatie",
|
||||||
"schedule": [
|
"schedule": [
|
||||||
{
|
{
|
||||||
"name": "Inleiding tot Telecommunicatie",
|
"course": "Inleiding tot Telecommunicatie",
|
||||||
"slots": [
|
"slots": [
|
||||||
{
|
{
|
||||||
"location": {
|
"location": {
|
||||||
|
@ -126,7 +126,7 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Wiskundige Modellering",
|
"course": "Wiskundige Modellering",
|
||||||
"slots": [
|
"slots": [
|
||||||
{
|
{
|
||||||
"location": {
|
"location": {
|
||||||
|
|
|
@ -11,6 +11,7 @@ course_urls = {
|
||||||
"Artificiële Intelligentie": "https://ufora.ugent.be/d2l/le/news/rss/439739/course?token=",
|
"Artificiële Intelligentie": "https://ufora.ugent.be/d2l/le/news/rss/439739/course?token=",
|
||||||
"Automaten, Berekenbaarheid en Complexiteit": "https://ufora.ugent.be/d2l/le/news/rss/439079/course?token=",
|
"Automaten, Berekenbaarheid en Complexiteit": "https://ufora.ugent.be/d2l/le/news/rss/439079/course?token=",
|
||||||
"Besturingssystemen": "https://ufora.ugent.be/d2l/le/news/rss/442814/course?token=",
|
"Besturingssystemen": "https://ufora.ugent.be/d2l/le/news/rss/442814/course?token=",
|
||||||
|
"Communicatienetwerken": "https://ufora.ugent.be/d2l/le/news/rss/447014/course?token=",
|
||||||
"Computationele Biologie": "https://ufora.ugent.be/d2l/le/news/rss/448904/course?token=",
|
"Computationele Biologie": "https://ufora.ugent.be/d2l/le/news/rss/448904/course?token=",
|
||||||
"Computerarchitectuur": "https://ufora.ugent.be/d2l/le/news/rss/439172/course?token=",
|
"Computerarchitectuur": "https://ufora.ugent.be/d2l/le/news/rss/439172/course?token=",
|
||||||
"Informatiebeveiliging": "https://ufora.ugent.be/d2l/le/news/rss/444476/course?token=",
|
"Informatiebeveiliging": "https://ufora.ugent.be/d2l/le/news/rss/444476/course?token=",
|
||||||
|
|
Loading…
Reference in New Issue