Skip to content

Instantly share code, notes, and snippets.

@nazareno
Created March 10, 2021 18:58
Show Gist options
  • Save nazareno/e18f8820bd13ef1dd7fe0695f7361acb to your computer and use it in GitHub Desktop.
Save nazareno/e18f8820bd13ef1dd7fe0695f7361acb to your computer and use it in GitHub Desktop.
Submissões LP2 Canvas -> Codepost
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