mirror of https://github.com/stijndcl/didier
Did some small formatting in les.py
parent
245a900c87
commit
08fe799a30
131
functions/les.py
131
functions/les.py
|
@ -93,67 +93,69 @@ def getCourses(schedule, day, week):
|
||||||
|
|
||||||
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 not in slot["time"]:
|
||||||
# Basic dict containing the course name & the class' time slot
|
continue
|
||||||
classDic = {"course": course["course"], "slot": slot}
|
|
||||||
|
|
||||||
# Class was canceled
|
# Basic dict containing the course name & the class' time slot
|
||||||
if "canceled" in slot and "weeks" in slot and week in slot["weeks"]:
|
classDic = {"course": course["course"], "slot": slot}
|
||||||
extras.append(classDic)
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Add online links for those at home
|
# Class was canceled
|
||||||
# Check if link hasn't been added yet
|
if "canceled" in slot and "weeks" in slot and week in slot["weeks"]:
|
||||||
if "online" in slot and not any(el["course"] == course["course"] and
|
extras.append(classDic)
|
||||||
# Avoid KeyErrors: if either of these don't have an online link yet,
|
continue
|
||||||
# add it as well
|
|
||||||
("online" not in el or el["online"] == slot["online"])
|
|
||||||
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)
|
|
||||||
|
|
||||||
if "zoom" in slot["online"].lower():
|
# Add online links for those at home
|
||||||
onlineDic = {"course": course["course"], "online": "ZOOM", "link": course["zoom"]}
|
# Check if link hasn't been added yet
|
||||||
onlineLinks.append(onlineDic)
|
if "online" in slot and not any(el["course"] == course["course"] and
|
||||||
|
# Avoid KeyErrors: if either of these don't have an online link yet,
|
||||||
|
# add it as well
|
||||||
|
("online" not in el or el["online"] == slot["online"])
|
||||||
|
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)
|
||||||
|
|
||||||
if "teams" in slot["online"].lower():
|
if "zoom" in slot["online"].lower():
|
||||||
onlineDic = {"course": course["course"], "online": "MS Teams", "link": course["msteams"]}
|
onlineDic = {"course": course["course"], "online": "ZOOM", "link": course["zoom"]}
|
||||||
onlineLinks.append(onlineDic)
|
onlineLinks.append(onlineDic)
|
||||||
|
|
||||||
# Add this class' bongo, msteams & zoom links
|
if "teams" in slot["online"].lower():
|
||||||
if "bongo" in course:
|
onlineDic = {"course": course["course"], "online": "MS Teams", "link": course["msteams"]}
|
||||||
classDic["slot"]["bongo"] = course["bongo"]
|
onlineLinks.append(onlineDic)
|
||||||
|
|
||||||
if "msteams" in course:
|
# Add this class' bongo, msteams & zoom links
|
||||||
classDic["slot"]["msteams"] = course["msteams"]
|
if "bongo" in course:
|
||||||
|
classDic["slot"]["bongo"] = course["bongo"]
|
||||||
|
|
||||||
if "zoom" in course:
|
if "msteams" in course:
|
||||||
classDic["slot"]["zoom"] = course["zoom"]
|
classDic["slot"]["msteams"] = course["msteams"]
|
||||||
|
|
||||||
if "custom" in course:
|
if "zoom" in course:
|
||||||
prev.append(classDic)
|
classDic["slot"]["zoom"] = course["zoom"]
|
||||||
|
|
||||||
# Check for special classes
|
if "custom" in course:
|
||||||
if "weeks" in slot and "online" not in slot:
|
prev.append(classDic)
|
||||||
if week in slot["weeks"]:
|
|
||||||
if "custom" not in course:
|
# Check for special classes
|
||||||
courses.append(classDic)
|
if "weeks" in slot and "online" not in slot:
|
||||||
extras.append(classDic)
|
if week in slot["weeks"]:
|
||||||
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 "custom" not in course:
|
|
||||||
courses.append(classDic)
|
|
||||||
extras.append(classDic)
|
|
||||||
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)
|
||||||
|
extras.append(classDic)
|
||||||
|
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 "custom" not in course:
|
||||||
|
courses.append(classDic)
|
||||||
|
extras.append(classDic)
|
||||||
|
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:
|
||||||
|
courses.append(classDic)
|
||||||
|
|
||||||
# Filter out normal courses that are replaced with special courses
|
# Filter out normal courses that are replaced with special courses
|
||||||
for extra in extras:
|
for extra in extras:
|
||||||
|
@ -245,18 +247,30 @@ def getLocation(slot):
|
||||||
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"],
|
# NOTE maybe this should be moved to a more general config area instead
|
||||||
slot["zoom"] if slot["online"] == "ZOOM" else slot["msteams"] if slot[
|
platforms = {
|
||||||
"online"] == "MS Teams" else
|
"ZOOM": slot["zoom"],
|
||||||
slot["bongo"])
|
"MS Teams": slot["msteams"],
|
||||||
|
}
|
||||||
|
|
||||||
|
return "online @ **[{}]({})**".format(
|
||||||
|
slot["online"],
|
||||||
|
platforms.get(slot["online"], slot["bongo"]
|
||||||
|
)
|
||||||
|
|
||||||
# Check for courses in multiple locations
|
# Check for courses in multiple locations
|
||||||
if "locations" in slot:
|
if "locations" in slot:
|
||||||
# Language - 'en' for the last one
|
# Language - 'en' for the last one
|
||||||
return ", ".join(getLocation(location) for location in slot["locations"][:-1]) \
|
return sum(
|
||||||
+ " en " + getLocation(slot["locations"][-1])
|
", ".join(
|
||||||
|
getLocation(location)
|
||||||
|
for location in slot["locations"][:-1]
|
||||||
|
),
|
||||||
|
" en ",
|
||||||
|
getLocation(slot["locations"][-1])
|
||||||
|
)
|
||||||
|
|
||||||
return "in {} {} {}".format(slot["campus"], slot["building"], slot["room"])
|
return "in {} {} {}".format(slot["campus"], slot["building"], slot["room"])
|
||||||
|
|
||||||
|
|
||||||
|
@ -273,9 +287,8 @@ def getTitle(day, dayDT, week):
|
||||||
# week += 1
|
# week += 1
|
||||||
|
|
||||||
day = day[0].upper() + day[1:].lower()
|
day = day[0].upper() + day[1:].lower()
|
||||||
|
titleString = f"{day} {dayDT.day:02}/{dayDT.month:02}/{dayDT.year}"
|
||||||
|
|
||||||
titleString = "{} {}/{}/{}".format(day, stringFormatters.leadingZero(dayDT.day),
|
|
||||||
stringFormatters.leadingZero(dayDT.month), dayDT.year)
|
|
||||||
return titleString, week
|
return titleString, week
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue