Skip to content

Instantly share code, notes, and snippets.

@jlumbroso
Last active February 20, 2023 23:14
Show Gist options
  • Save jlumbroso/c08f573621f36a35b5a96d8c426505cd to your computer and use it in GitHub Desktop.
Save jlumbroso/c08f573621f36a35b5a96d8c426505cd to your computer and use it in GitHub Desktop.
codePost snippet to programmatically dump all the submission times (in UTC) for all submissions of an assignment in a CSV file
import codepost
# fancy progress bar if available
try:
from tqdm import tqdm
except ModuleNotFoundError:
# dummy replacement that does nothing
tqdm = lambda x: x
# variable parameters
# get the API key here: https://codepost.io/settings
API_KEY = "... see above where to get this ..."
COURSE_NAME = "COS126"
COURSE_TERM = "F2022"
ASSIGNMENT = "Hello"
# format of the output filename
OUTPUT_FILENAME = f"{COURSE_NAME}_{COURSE_TERM}_{ASSIGNMENT}_submission_dates.csv"
# 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()
# helper method
def select_all_but(lst, val):
"""
Computes a copy of `lst` in which all occurrences of `val` are
removed.
"""
return list(filter(
lambda x: x != val,
lst
))
# prepare header of the CSV file
output_lines = ["student,submission_id,date_uploaded,grade,partners"]
# iterate over every submission and output upload date
for submission in tqdm(assignment.list_submissions()):
# output one line per student for partnered submissions
# (dateUploaded is of the format 2022-12-14T02:02:52.178772Z with UTC timezone
# see: https://en.wikipedia.org/wiki/ISO_8601#Coordinated_Universal_Time_(UTC) )
for student in submission.students:
output_lines.append(
"{student},{id},{dateUploaded},{grade},{partners}".format(
student=student,
partners=";".join(select_all_but(submission.students, student)),
**submission._data
)
)
# write file
open(OUTPUT_FILENAME, "w").write("\n".join(output_lines))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment