mirror of https://github.com/stijndcl/didier
Fixed incorrect links in schedules, schedules now show all links of this day
parent
474ad85a46
commit
f77e465076
|
@ -6,16 +6,10 @@
|
||||||
"slots": [
|
"slots": [
|
||||||
{
|
{
|
||||||
"online": "Bongo Virtual Classroom",
|
"online": "Bongo Virtual Classroom",
|
||||||
"campus": "Sterre",
|
|
||||||
"building": "S8",
|
|
||||||
"room": "LES 3.1",
|
|
||||||
"time": ["maandag", 1000, 1230]
|
"time": ["maandag", 1000, 1230]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"online": "ZOOM",
|
"online": "ZOOM",
|
||||||
"campus": "Sterre",
|
|
||||||
"building": "S8",
|
|
||||||
"room": "LES 2.4",
|
|
||||||
"time": ["vrijdag", 1300, 1530]
|
"time": ["vrijdag", 1300, 1530]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -24,34 +18,14 @@
|
||||||
"course": "Systeemprogrammeren",
|
"course": "Systeemprogrammeren",
|
||||||
"bongo": "https://ufora.ugent.be/d2l/ext/rp/222035/lti/framedlaunch/7f4120b3-8827-44ad-8b02-a79066c396cf",
|
"bongo": "https://ufora.ugent.be/d2l/ext/rp/222035/lti/framedlaunch/7f4120b3-8827-44ad-8b02-a79066c396cf",
|
||||||
"slots": [
|
"slots": [
|
||||||
{
|
|
||||||
"campus": "Sterre",
|
|
||||||
"building": "S8",
|
|
||||||
"room": "LES 2.1",
|
|
||||||
"time": ["donderdag", 1430, 1700]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"online": "Bongo Virtual Classroom",
|
"online": "Bongo Virtual Classroom",
|
||||||
"weeks": [1],
|
|
||||||
"group": 1,
|
|
||||||
"campus": "Sterre",
|
|
||||||
"building": "S4",
|
|
||||||
"room": "LES 0.1",
|
|
||||||
"time": ["maandag", 1430, 1700]
|
"time": ["maandag", 1430, 1700]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"online": "Bongo Virtual Classroom",
|
"online": "Bongo Virtual Classroom",
|
||||||
"weeks": [1],
|
|
||||||
"time": ["donderdag", 1430, 1700]
|
"time": ["donderdag", 1430, 1700]
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"weeks": [2],
|
|
||||||
"group": 2,
|
|
||||||
"campus": "Sterre",
|
|
||||||
"building": "S4",
|
|
||||||
"room": "LES 0.1",
|
|
||||||
"time": ["maandag", 1430, 1700]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"weeks": [3],
|
"weeks": [3],
|
||||||
"canceled": true,
|
"canceled": true,
|
||||||
|
@ -73,73 +47,44 @@
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": ["maandag", 1430, 1700]
|
"time": ["maandag", 1430, 1700]
|
||||||
},
|
|
||||||
{
|
|
||||||
"weeks": [5],
|
|
||||||
"group": 1,
|
|
||||||
"locations": [
|
|
||||||
{
|
|
||||||
"campus": "Sterre",
|
|
||||||
"building": "S8",
|
|
||||||
"room": "LES 0.1 Victor Van Straelen"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"campus": "Sterre",
|
|
||||||
"building": "S9",
|
|
||||||
"room": "3.1 Konrad Zuse"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"time": ["maandag", 1430, 1700]
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"course": "AD 2",
|
"course": "AD 2",
|
||||||
"bongo": "https://ufora.ugent.be/d2l/ext/rp/222018/lti/framedlaunch/7f4120b3-8827-44ad-8b02-a79066c396cf",
|
"bongo": "https://ufora.ugent.be/d2l/ext/rp/222018/lti/framedlaunch/7f4120b3-8827-44ad-8b02-a79066c396cf",
|
||||||
|
"msteams": "https://teams.microsoft.com/_?culture=nl-nl&country=NL&lm=deeplink&lmsrc=homePageWeb&cmpid=WebSignIn#/conversations/19:8ee7593d50924201a43ed9373dd6b05d@thread.v2?ctx=chat",
|
||||||
|
"zoom": "https://ufora.ugent.be/d2l/ext/rp/222018/lti/framedlaunch/556e197e-e87b-4c27-be5d-53adc7a41826",
|
||||||
"slots": [
|
"slots": [
|
||||||
{
|
{
|
||||||
"campus": "Sterre",
|
"online": "Bongo Virtual Classroom",
|
||||||
"building": "S9",
|
"time": ["dinsdag", 1300, 1400]
|
||||||
"room": "A3",
|
|
||||||
"time": ["dinsdag", 1300, 1530]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"campus": "Sterre",
|
"online": "ZOOM",
|
||||||
"building": "S9",
|
"time": ["dinsdag", 1400, 1530]
|
||||||
"room": "A3",
|
},
|
||||||
|
{
|
||||||
|
"online": "Bongo Virtual Classroom",
|
||||||
"time": ["vrijdag", 830, 930]
|
"time": ["vrijdag", 830, 930]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"locations": [
|
"online": "MS Teams",
|
||||||
{
|
|
||||||
"campus": "Sterre",
|
|
||||||
"building": "S8",
|
|
||||||
"room": "Victor Van Straelen"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"campus": "Sterre",
|
|
||||||
"building": "S9",
|
|
||||||
"room": "3.1 Konrad Zuse"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"time": ["vrijdag", 1000, 1100]
|
"time": ["vrijdag", 1000, 1100]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"course": "Communicatienetwerken",
|
"course": "Communicatienetwerken",
|
||||||
|
"zoom": "https://ufora.ugent.be/d2l/ext/rp/221184/lti/framedlaunch/556e197e-e87b-4c27-be5d-53adc7a41826",
|
||||||
"slots": [
|
"slots": [
|
||||||
{
|
{
|
||||||
"campus": "Ardoyen",
|
"online": "ZOOM",
|
||||||
"building": "Locus",
|
"time": ["woensdag", 1100, 1200]
|
||||||
"room": "Resto Locus",
|
|
||||||
"time": ["woensdag", 1000, 1230]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"campus": "Ardoyen",
|
"online": "ZOOM",
|
||||||
"building": "Locus",
|
"time": ["woensdag", 1430, 1600]
|
||||||
"room": "Resto Locus",
|
|
||||||
"time": ["woensdag", 1430, 1700]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"weeks": [4, 7],
|
"weeks": [4, 7],
|
||||||
|
@ -170,32 +115,14 @@
|
||||||
"slots": [
|
"slots": [
|
||||||
{
|
{
|
||||||
"online": "Bongo Virtual Classroom",
|
"online": "Bongo Virtual Classroom",
|
||||||
"campus": "Sterre",
|
|
||||||
"building": "S12",
|
|
||||||
"room": "Auditorium 1",
|
|
||||||
"time": ["dinsdag", 1600, 1700]
|
"time": ["dinsdag", 1600, 1700]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"locations": [
|
|
||||||
{
|
|
||||||
"campus": "Sterre",
|
|
||||||
"building": "S9",
|
|
||||||
"room": "1.1 Alan Turing"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"campus": "Sterre",
|
|
||||||
"building": "S9",
|
|
||||||
"room": "3.1 Konrad Zuse"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"online": "Bongo Virtual Classroom",
|
"online": "Bongo Virtual Classroom",
|
||||||
"time": ["donderdag", 830, 1100]
|
"time": ["donderdag", 830, 1100]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"online": "Bongo Virtual Classroom",
|
"online": "Bongo Virtual Classroom",
|
||||||
"campus": "Sterre",
|
|
||||||
"building": "S9",
|
|
||||||
"room": "A2",
|
|
||||||
"time": ["donderdag", 1300, 1400]
|
"time": ["donderdag", 1300, 1400]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
104
functions/les.py
104
functions/les.py
|
@ -4,6 +4,10 @@ from functions import config, timeFormatters, stringFormatters
|
||||||
from functions.numbers import clamp
|
from functions.numbers import clamp
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
# TODO use constants & enums instead of hardcoding platform names
|
||||||
|
# also make the naming in the jsons more consistent
|
||||||
|
|
||||||
def createCourseString(courses):
|
def createCourseString(courses):
|
||||||
courseString = ""
|
courseString = ""
|
||||||
for course in sorted(courses, key=lambda item: item["slot"]["time"][1]):
|
for course in sorted(courses, key=lambda item: item["slot"]["time"][1]):
|
||||||
|
@ -42,15 +46,23 @@ def createEmbed(day, dayDatetime, semester, year, schedule):
|
||||||
if extras:
|
if extras:
|
||||||
embed.add_field(name="Extra", value="\n".join(getExtras(extra) for extra in extras), inline=False)
|
embed.add_field(name="Extra", value="\n".join(getExtras(extra) for extra in extras), inline=False)
|
||||||
|
|
||||||
# Add online links
|
# TODO uncomment this when covid rules slow down
|
||||||
|
# Add online links - temporarily removed because everything is online right now
|
||||||
if online:
|
if online:
|
||||||
embed.add_field(name="Online Links", value="\n".join(getLink(onlineClass) for onlineClass in online))
|
uniqueLinks: dict = getUniqueLinks(online)
|
||||||
|
embed.add_field(name="Online Links", value="\n".join(
|
||||||
|
sorted(getLinks(onlineClass, links) for onlineClass, links in uniqueLinks.items())))
|
||||||
|
|
||||||
embed.set_footer(text="Semester {} | Lesweek {}".format(semester, round(week)))
|
embed.set_footer(text="Semester {} | Lesweek {}".format(semester, round(week)))
|
||||||
return embed
|
return embed
|
||||||
|
|
||||||
|
|
||||||
def findDate(targetWeekday):
|
def findDate(targetWeekday):
|
||||||
|
"""
|
||||||
|
Function that finds the datetime object that corresponds to
|
||||||
|
the next occurence of [targetWeekday].
|
||||||
|
:param targetWeekday: The weekday to find
|
||||||
|
"""
|
||||||
now = timeFormatters.dateTimeNow()
|
now = timeFormatters.dateTimeNow()
|
||||||
while now.weekday() != targetWeekday:
|
while now.weekday() != targetWeekday:
|
||||||
now = now + datetime.timedelta(days=1)
|
now = now + datetime.timedelta(days=1)
|
||||||
|
@ -58,14 +70,23 @@ def findDate(targetWeekday):
|
||||||
|
|
||||||
|
|
||||||
def getCourses(schedule, day, week):
|
def getCourses(schedule, day, week):
|
||||||
|
"""
|
||||||
|
Function that creates a list of all courses of this day,
|
||||||
|
a list of all online links, and extra information for these courses.
|
||||||
|
:param schedule: A user's (customized) schedule
|
||||||
|
:param day: The current weekday
|
||||||
|
:param week: The current week
|
||||||
|
"""
|
||||||
# Add all courses & their corresponding times + locations of today
|
# Add all courses & their corresponding times + locations of today
|
||||||
courses = []
|
courses = []
|
||||||
extras = []
|
extras = []
|
||||||
prev = []
|
prev = []
|
||||||
onlineLinks = []
|
onlineLinks = []
|
||||||
|
|
||||||
for course in schedule:
|
for course in schedule:
|
||||||
for slot in course["slots"]:
|
for slot in course["slots"]:
|
||||||
if day in slot["time"]:
|
if day in slot["time"]:
|
||||||
|
# Basic dict containing the course name & the class' time slot
|
||||||
classDic = {"course": course["course"], "slot": slot}
|
classDic = {"course": course["course"], "slot": slot}
|
||||||
|
|
||||||
# Class was canceled
|
# Class was canceled
|
||||||
|
@ -74,18 +95,34 @@ def getCourses(schedule, day, week):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Add online links for those at home
|
# Add online links for those at home
|
||||||
if not any(el["course"] == course["course"] for el in onlineLinks):
|
# Check if link hasn't been added yet
|
||||||
if "bongo" in course:
|
if not any(el["course"] == course["course"] and
|
||||||
onlineDic = {"course": course["course"], "online": "Bongo Virtual Classroom", "link": course["bongo"]}
|
# Avoid KeyErrors: if either of these don't have an online link yet,
|
||||||
onlineLinks.append(onlineDic)
|
# add it as well
|
||||||
elif "zoom" in course:
|
("online" not in el or "online" not in slot or el["online"] == slot["online"])
|
||||||
onlineDic = {"course": course["course"], "online": "Zoom", "link": course["zoom"]}
|
for el in onlineLinks):
|
||||||
|
# Some courses have multiple links on the same day,
|
||||||
|
# add all of them
|
||||||
|
if "bongo" in slot["online"].lower():
|
||||||
|
onlineDic = {"course": course["course"], "online": "Bongo Virtual Classroom",
|
||||||
|
"link": course["bongo"]}
|
||||||
onlineLinks.append(onlineDic)
|
onlineLinks.append(onlineDic)
|
||||||
|
|
||||||
# Add this class' bongo & zoom links
|
if "zoom" in slot["online"].lower():
|
||||||
|
onlineDic = {"course": course["course"], "online": "ZOOM", "link": course["zoom"]}
|
||||||
|
onlineLinks.append(onlineDic)
|
||||||
|
|
||||||
|
if "teams" in slot["online"].lower():
|
||||||
|
onlineDic = {"course": course["course"], "online": "MS Teams", "link": course["msteams"]}
|
||||||
|
onlineLinks.append(onlineDic)
|
||||||
|
|
||||||
|
# Add this class' bongo, msteams & zoom links
|
||||||
if "bongo" in course:
|
if "bongo" in course:
|
||||||
classDic["slot"]["bongo"] = course["bongo"]
|
classDic["slot"]["bongo"] = course["bongo"]
|
||||||
|
|
||||||
|
if "msteams" in course:
|
||||||
|
classDic["slot"]["msteams"] = course["msteams"]
|
||||||
|
|
||||||
if "zoom" in course:
|
if "zoom" in course:
|
||||||
classDic["slot"]["zoom"] = course["zoom"]
|
classDic["slot"]["zoom"] = course["zoom"]
|
||||||
|
|
||||||
|
@ -99,11 +136,14 @@ def getCourses(schedule, day, week):
|
||||||
courses.append(classDic)
|
courses.append(classDic)
|
||||||
extras.append(classDic)
|
extras.append(classDic)
|
||||||
elif "weeks" in slot and "online" in slot and "group" not in slot:
|
elif "weeks" in slot and "online" in slot and "group" not in slot:
|
||||||
|
# This class is only online for this week
|
||||||
if week in slot["weeks"]:
|
if week in slot["weeks"]:
|
||||||
if "custom" not in course:
|
if "custom" not in course:
|
||||||
courses.append(classDic)
|
courses.append(classDic)
|
||||||
extras.append(classDic)
|
extras.append(classDic)
|
||||||
else:
|
else:
|
||||||
|
# Nothing special happening, just add it to the list of courses
|
||||||
|
# in case this is a course for everyone in this year
|
||||||
if "custom" not in course:
|
if "custom" not in course:
|
||||||
courses.append(classDic)
|
courses.append(classDic)
|
||||||
|
|
||||||
|
@ -126,6 +166,10 @@ def getCourses(schedule, day, week):
|
||||||
|
|
||||||
|
|
||||||
def getExtras(extra):
|
def getExtras(extra):
|
||||||
|
"""
|
||||||
|
Function that returns a formatted string giving clear info
|
||||||
|
when a course is happening somewhere else (or canceled).
|
||||||
|
"""
|
||||||
start = timeFormatters.timeFromInt(extra["slot"]["time"][1])
|
start = timeFormatters.timeFromInt(extra["slot"]["time"][1])
|
||||||
end = timeFormatters.timeFromInt(extra["slot"]["time"][2])
|
end = timeFormatters.timeFromInt(extra["slot"]["time"][2])
|
||||||
|
|
||||||
|
@ -153,16 +197,52 @@ def getExtras(extra):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def getLink(onlineClass):
|
def getUniqueLinks(onlineClasses):
|
||||||
return "{}: **[{}]({})**".format(onlineClass["course"], onlineClass["online"], onlineClass["link"])
|
"""
|
||||||
|
Function that returns a dict of all online unique online links for every class
|
||||||
|
in case some classes have multiple links on the same day.
|
||||||
|
"""
|
||||||
|
# Create a list of all unique course names
|
||||||
|
courseNames = list(set(oc["course"] for oc in onlineClasses))
|
||||||
|
uniqueLinks: dict = {}
|
||||||
|
|
||||||
|
# Add every link of every class into the dict
|
||||||
|
for name in courseNames:
|
||||||
|
uniqueLinks[name] = {}
|
||||||
|
for oc in onlineClasses:
|
||||||
|
if oc["course"] == name:
|
||||||
|
# Add the link for this platform
|
||||||
|
uniqueLinks[name][oc["online"]] = oc["link"]
|
||||||
|
|
||||||
|
return uniqueLinks
|
||||||
|
|
||||||
|
|
||||||
|
def getLinks(onlineClass, links):
|
||||||
|
"""
|
||||||
|
Function that returns a formatted string giving a hyperlink
|
||||||
|
to every online link for this class today.
|
||||||
|
"""
|
||||||
|
return "{}: {}".format(onlineClass,
|
||||||
|
" | ".join(
|
||||||
|
["**[{}]({})**".format(platform, url) for platform, url in
|
||||||
|
links.items()])
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def getLocation(slot):
|
def getLocation(slot):
|
||||||
|
"""
|
||||||
|
Function that returns a formatted string indicating where this course
|
||||||
|
is happening.
|
||||||
|
"""
|
||||||
if "canceled" in slot:
|
if "canceled" in slot:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
# TODO fix this because it's ugly
|
||||||
if "online" in slot:
|
if "online" in slot:
|
||||||
return "online @ **[{}]({})**".format(slot["online"], slot["zoom"] if slot["online"] == "ZOOM" else slot["bongo"])
|
return "online @ **[{}]({})**".format(slot["online"],
|
||||||
|
slot["zoom"] if slot["online"] == "ZOOM" else slot["msteams"] if slot[
|
||||||
|
"online"] == "MS Teams" else
|
||||||
|
slot["bongo"])
|
||||||
|
|
||||||
# Check for courses in multiple locations
|
# Check for courses in multiple locations
|
||||||
if "locations" in slot:
|
if "locations" in slot:
|
||||||
|
|
Loading…
Reference in New Issue