Created
March 10, 2021 18:58
-
-
Save nazareno/e18f8820bd13ef1dd7fe0695f7361acb to your computer and use it in GitHub Desktop.
Submissões LP2 Canvas -> Codepost
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 csv, sys, os | |
from zipfile import ZipFile | |
from io import BytesIO | |
alunos = {} | |
csv_alunos = sys.argv[2] | |
zip_submissions = sys.argv[1] | |
with open(csv_alunos, newline='') as csvfile: | |
reader = csv.DictReader(csvfile) | |
for row in reader: | |
# print(row) | |
alunos[row['codigo']] = row['email'] | |
out_dir = "saida" | |
os.mkdir(out_dir) | |
found = 0 | |
with ZipFile(zip_submissions) as myzip: | |
for myfile_ in myzip.infolist(): | |
if not myfile_.filename.lower().endswith('.zip'): | |
continue | |
fname = myfile_.filename | |
user_id = myfile_.filename.split('_')[1] | |
if user_id == "LATE": | |
user_id = myfile_.filename.split('_')[2] | |
if user_id not in alunos: | |
print("\nMISSING: " + fname) | |
#exit(1) | |
continue | |
else: | |
print('.', end='', flush=True) | |
found += 1 | |
saida_aluno = out_dir + "/" + alunos[user_id] + "@ccc.ufcg.edu.br" | |
os.mkdir(saida_aluno) | |
with myzip.open(myfile_) as myfile: | |
zfiledata = BytesIO(myfile.read()) | |
with ZipFile(zfiledata) as userzip: | |
for userfile_ in userzip.infolist(): | |
if not userfile_.filename.lower().endswith('.java'): | |
continue | |
userzip.extract(userfile_, path = saida_aluno) | |
print("Encontramos ", found, " trabalhos") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment