Created
May 10, 2022 00:26
-
-
Save jlumbroso/386bac37e4604191fdeb6b609c2a74ac to your computer and use it in GitHub Desktop.
codePost snippet to export a CSV file of the links to all submissions for a given assignment
This file contains hidden or 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 | |
# for CSV export, see: https://comma.readthedocs.io/en/latest/ | |
import comma | |
# how to form a codePost submission link from the submission id | |
CODEPOST_SUBMISSION_LINK_PATTERN = "https://codepost.io/code/{id}" | |
# 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 = "Final Project Implementation" | |
# 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) | |
# retrieve submissions | |
submissions = assignment.list_submissions() | |
# build a dictionary of student -> submission link | |
submission_links = list() | |
for submission in submissions: | |
submission_link = CODEPOST_SUBMISSION_LINK_PATTERN.format(id=submission.id) | |
for student in submission.students: | |
submission_links.append({ | |
"student": student, | |
"codePost_submission_link": submission_link, | |
}) | |
# export CSV using the comma package | |
csv_data = comma.dump(submission_links) | |
csv_filename = "{course_name}_{course_term}-{assignment}-links.csv".format( | |
course_name=COURSE_NAME, | |
course_term=COURSE_TERM, | |
assignment=ASSIGNMENT | |
).replace(" ", "_").lower() | |
open(csv_filename, "w").write(csv_data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment