def creat_new_assignment(reference_assignment: canvasapi.assignment, course: canvasapi.canvas.Course, students_dict: typing.Dict[int, Student], assignment_group_id): """ --creates a new assignment inside the course :param reference_assignment: the new assignment inherits its name from the refrence assignment :param course: the course in which the assignment is created :param students_dict: student's dictionary is used to generate grades and upload the the new assignment :param assignment_group_id :side effects: the new assignment will not show up in the assignments view until the view is updated """ assignment = {} name = ("Peer Review For " + reference_assignment.name) number_of_times_name_used = 0 assignments = course.get_assignments() for a in assignments: if name in a.name: number_of_times_name_used = number_of_times_name_used + 1 if number_of_times_name_used > 0: name = ("Peer Review For " + reference_assignment.name ) + "(" + str(number_of_times_name_used) + ")" assignment['name'] = name assignment['published'] = True assignment['points_possible'] = 100 assignment['grading_type'] = "percent" assignment['assignment_group_id'] = assignment_group_id new_assignment = course.create_assignment(assignment) new_assignment.submissions_bulk_update( grade_data=make_grade_dictionary(students_dict))
def extract_assignments(c: canvasapi.canvas.Course): for ass in c.get_assignments(): # `ass.description` might be outdated so we have to make a separate request html_to_parse = c.get_assignment(ass.id).description if html_to_parse is None: continue # Sometimes file links might be broken, sometimes the Canvas API just returns nonsense # yield from map(c.get_file, extract_file_ids(html_to_parse)) yield from file_extractor(c, extract_file_ids(html_to_parse))
def get_assignments(course: canvasapi.canvas.Course) -> [canvasapi.assignment]: """ :param course: canvas course object :return: a list of canvas assignment objects """ return course.get_assignments()