Skip to content

Instantly share code, notes, and snippets.

@abhikpal
Created September 22, 2018 06:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abhikpal/8c3ba914e02885cabddb2b2c569c9a4c to your computer and use it in GitHub Desktop.
Save abhikpal/8c3ba914e02885cabddb2b2c569c9a4c to your computer and use it in GitHub Desktop.
import csv
import os
import sys
import subprocess
def filter_keeds(zfile, klist='kids.csv', exdir='tmp'):
"""Filter the students.
:param zfile: The (zip) file with all homework submissions.
:param klist: CSV file containing list of students
(NAME,CAMPUS_NET_LOGIN)
:param exdir: The name of the directory to extract files to
(defaults to 'tmp')
:param tdir: Target directory. All extracted files will be moved
to this folder.
"""
ta_group_submitted = {}
with open(klist, 'r') as kids_file:
reader = csv.reader(kids_file)
for row in reader:
ta_group_submitted[row[0]] = False
subprocess.call(["unzip", zfile, "-d", exdir])
all_submissions = os.listdir(exdir)
for submission in all_submissions:
student_name = submission.split('_')[0]
if student_name not in ta_group_submitted.keys():
subprocess.call(["rm", "-rf", os.path.join(exdir, submission)])
else:
ta_group_submitted[student_name] = True
print("\nNo submissions found for:")
for student, submitted in ta_group_submitted.items():
if not submitted:
print(f"* {student}")
if __name__ == '__main__':
try:
homework_source = sys.argv[1]
homework_number = sys.argv[2]
except IndexError:
print("USAGE:")
print("\t$ python filter.py [ALL SUBMISSIONS (ZIP)] [HOMEWORK NUMBER]")
exit(1)
filter_keeds(homework_source, exdir=f'hw{str(homework_number).zfill(2)}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment