Last active
March 13, 2022 20:09
-
-
Save jlumbroso/c42955a6a76706209cdbc841b99c2ac3 to your computer and use it in GitHub Desktop.
codePost snippet to automatically finalize all submissions of an assignment, and automatically add a comment that sets the grade of the submission
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import codepost | |
# variable parameters | |
# get the API key here: https://codepost.io/settings | |
API_KEY = "... see above where to get this ..." | |
COURSE_NAME = "COS126" | |
COURSE_TERM = "S2022" | |
ASSIGNMENT = "Programming Exam 1" | |
# authenticate | |
codepost.configure_api_key(API_KEY) | |
# retrieve the course, and then the assignment | |
# (will crash if the user of the API key doesn't have access to the course) | |
course = codepost.course.list_available(name=COURSE_NAME, period=COURSE_TERM)[0] | |
assignment = course.assignments.by_name(name=ASSIGNMENT) | |
# iterate over all submissions | |
for submission in assignment.list_submissions(): | |
# claim submission (must assign a grader, here I assign myself) | |
submission.grader = "lumbroso@princeton.edu" | |
# save changes (necessary to be able to assign comments) | |
submission.save() | |
# then select a file on which to add a comment | |
test_file = submission.files.by_name(name="TESTS.txt") | |
# remove all previous comments | |
# (to avoid duplicates, if we rerun this process several times) | |
for comment in test_file.comments: | |
comment.delete() | |
grade = 30.0 # you could load this from other place | |
# describe and create the comment | |
comment = { | |
'file': test_file.id, | |
'text': ( | |
"Your final grade is: {} / 30.0\n\n" + | |
"Please look at TESTS.txt for a detailed computation." | |
).format(grade), | |
'pointDelta': -grade, | |
'rubricComment': None, | |
'startChar': 0, | |
'endChar': 1, | |
'startLine': 1, | |
'endLine': 1, | |
} | |
codepost.comment.create(**comment) | |
# finalize the submission | |
# (so it is visible to students, once the assignment is "published") | |
submission.isFinalized = True | |
submission.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Read more about this snippet in the corresponding Medium article:
https://medium.com/@jeremie.lumbroso/how-to-automatically-finalize-all-submissions-in-codepost-6650badfeed7