Example #1
0
def fetchCourses(numQuartersAgo):
    TERM_LIST_URL = "https://andromeda.miragespace.net/slugsurvival/data/fetch/terms.json"
    TERM_INFO_URL = "https://andromeda.miragespace.net/slugsurvival/data/fetch/terms/"
    COURSE_INFO_URL = "https://andromeda.miragespace.net/slugsurvival/data/fetch/courses/"

    ucsc_term = getQuarter(TERM_LIST_URL, numQuartersAgo)
    term_id = ucsc_term["code"]
    quarter = ucsc_term["name"].split()[1] + " " + ucsc_term["name"].split()[0]

    term_data = fetcherHelper.sendGetRequest(TERM_INFO_URL + str(term_id) +
                                             ".json")
    course_data = fetcherHelper.sendGetRequest(COURSE_INFO_URL + str(term_id) +
                                               ".json")

    all_courses = {}
    # Getting the data available from the term API (name, class time)
    for course_prefix in term_data:
        for course in term_data[course_prefix]:
            new_course = Course(id=course["num"], quarter=quarter)

            short_name = course_prefix + " " + course["c"]
            full_name = short_name + " - " + course["s"] + ": " + course["n"]
            new_course.name = full_name

            class_time = course["loct"][0]["t"]
            new_course.geCodes = course_data[str(new_course.id)]["ge"]
            prerequisites = course_data[str(new_course.id)]["re"]
            if prerequisites is not None:
                new_course.prerequisites = re.findall(
                    "[A-Z]{1,5} [0-9A-Z]{1,3}", prerequisites)

            if (class_time != None and class_time != False):
                try:
                    new_course.time = (class_time["time"]["start"],
                                       class_time["time"]["end"])
                    all_courses[short_name] = new_course
                except Exception as e:
                    pass

    return all_courses