Skip to content

Instantly share code, notes, and snippets.

@jlumbroso
Last active December 1, 2022 03:18
Show Gist options
  • Save jlumbroso/ede3a74ef334187f7994542f0938b2c7 to your computer and use it in GitHub Desktop.
Save jlumbroso/ede3a74ef334187f7994542f0938b2c7 to your computer and use it in GitHub Desktop.
codePost snippet to programmatically reassign students/partnerships on already-uploaded submissions
import codepost
# variable parameters
# get the API key here: https://codepost.io/settings
API_KEY = "... see above where to get this ..."
# mapping a codePost ID to students
# (note that this could be loaded from a CSV file)
partnerships = {
65490: ["student1@princeton.edu", "student2@princeton.edu"],
}
# authenticate
codepost.configure_api_key(API_KEY)
for submission_id, students in partnerships.items():
# retrieve the submission
try:
submission = codepost.submission.retrieve(id=submission_id)
except:
print("Error retrieve submission with ID {}".format(submission_id))
submission = None
if submission is None:
continue
# change the students
#
# NOTE: currently, because we are assigning an object to
# the property "students", we need to cast it to the same
# dynamic list data type as the list we are replacing (this
# is a bug of the SDK that will be fixed in an upcoming
# version)
submission.students = type(submission.students)(students)
try:
submission.save()
except:
print("Error saving submission with ID {} from {} to: {}".format(
submission_id,
submission.students,
students
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment