Skip to content

Commit

Permalink
add courses run in prev years to /dump route (#1114)
Browse files Browse the repository at this point in the history
  • Loading branch information
martanman authored Apr 4, 2024
1 parent 8a6099c commit 0d1fb25
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions backend/server/routers/courses.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,34 @@ def get_jsonified_course(courseCode: str) -> str:
def get_courses() -> list[Dict]:
"""
Gets all courses in the database.
(For CSElectives), by yours truly, Aimen 💫
(For CSElectives)
"""
courses = []
for course in coursesCOL.find():
course["is_legacy"] = False

def generate_course(course, is_legacy):
course["is_legacy"] = is_legacy
course.setdefault("school", None)
del course["_id"]
with suppress(KeyError):
del course["exclusions"]["leftover_plaintext"]
courses.append(course)
return courses
return course

all_courses = fetch_all_courses()

courses = dict()
for course in coursesCOL.find():
courses[course["code"]] = generate_course(course, False)

years = list(map(str, sorted(ARCHIVED_YEARS, reverse=True)))
for course_code in all_courses:
if course_code in courses:
continue
for year in years:
course = archivesDB[year].find_one({"code": course_code})
if course:
courses[course["code"]] = generate_course(course, True)
break

return list(courses.values())

@router.get(
"/getCourse/{courseCode}",
Expand Down

0 comments on commit 0d1fb25

Please sign in to comment.