Last active
March 15, 2024 07:10
-
-
Save bfritscher/b039cc4d1e33efc884a37fb7ddda923f to your computer and use it in GitHub Desktop.
sort github classroom assignments into sub groups
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 glob | |
import os | |
import csv | |
from collections import defaultdict | |
# Usage on windows | |
# gh classroom clone student-repos | |
# add classroom_roster.csv | |
# rename root folder and match prefix | |
assignment_prefix = 'vuejs-evaluation-ne-' | |
index = {} | |
folders = defaultdict(lambda: 'other') | |
folders['he-arc.ch'] = 'ne' | |
folders['etu.hesge.ch'] = 'ge' | |
folders['students.hevs.ch'] = 'vs' | |
with open('classroom_roster.csv') as csvfile: | |
spamreader = csv.DictReader(csvfile) | |
for row in spamreader: | |
index[f"{assignment_prefix}{row['github_username']}"] = row | |
from pathlib import Path | |
for fd in ['ne', 'ge', 'vs', 'other']: | |
Path(f"./sorted_{assignment_prefix}/{fd}").mkdir(parents=True, exist_ok=True) | |
# for folder move it to the right folder and rename it | |
assignments = list([fd for fd in glob.glob('*', root_dir=assignment_prefix)]) | |
print(f"found assignments {len(assignments)}") | |
for fd in assignments: | |
dest_dir = 'other' | |
ident = fd | |
if fd in index: | |
row = index[fd] | |
if '@' in row['identifier']: | |
dest_dir = folders[row['identifier'].split('@')[1]] | |
ident = f"{row['identifier'].split('@')[0]}_{fd}" | |
print(dest_dir, fd, row['identifier']) | |
src = os.path.join(assignment_prefix, fd) | |
dest = os.path.join(f"sorted_{assignment_prefix}", dest_dir, ident) | |
cmd = f"xcopy {src} {dest} /E/H/C/I" | |
print(cmd) | |
os.system(cmd) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment