77 lines
1.7 KiB
Python
77 lines
1.7 KiB
Python
|
#!/usr/bin/env python
|
||
|
# encoding: utf-8
|
||
|
|
||
|
import os
|
||
|
from string import Template
|
||
|
import subprocess
|
||
|
import shlex
|
||
|
|
||
|
classes = {"3B" : []}
|
||
|
|
||
|
def build_student(infos):
|
||
|
return {'nom':infos[1].capitalize(),
|
||
|
"prenom": infos[2].capitalize(),
|
||
|
"id" : infos[4],
|
||
|
"mdp" : infos[5][:-1]}
|
||
|
|
||
|
def mixing(eleve1, eleve2 = None):
|
||
|
ans = {}
|
||
|
for (k,i) in eleve1.items():
|
||
|
ans[k+"1"] = i
|
||
|
if eleve2:
|
||
|
for (k,i) in eleve2.items():
|
||
|
ans[k+"2"] = i
|
||
|
else:
|
||
|
for (k,i) in eleve1.items():
|
||
|
ans[k+"2"] = "None"
|
||
|
return ans
|
||
|
|
||
|
|
||
|
with open('./comptes_eleves_LaboMEP.csv', 'r', encoding="latin1") as accounts_f:
|
||
|
for line in accounts_f:
|
||
|
line_l = line.split(";")
|
||
|
if line_l[0] in classes:
|
||
|
classes[line_l[0]] += [build_student(line_l)]
|
||
|
|
||
|
|
||
|
for (classe, eleves) in classes.items():
|
||
|
path = "./"+classe
|
||
|
|
||
|
if not os.path.exists(path):
|
||
|
os.mkdir("./" + classe)
|
||
|
|
||
|
os.chdir("./" + classe)
|
||
|
|
||
|
i = 0
|
||
|
while i < len(eleves):
|
||
|
dest_file= "./pres_{i}.tex".format(i = int(i/2))
|
||
|
print(dest_file)
|
||
|
|
||
|
if i <= len(eleves) - 2:
|
||
|
deux_eleves = mixing(eleves[i], eleves[i+1])
|
||
|
else:
|
||
|
deux_eleves = mixing(eleves[i])
|
||
|
|
||
|
|
||
|
|
||
|
with open("../pres_labomep.tex", 'r') as accounts_f:
|
||
|
with open(dest_file, 'w') as f:
|
||
|
for l in accounts_f.readlines():
|
||
|
f.write(Template(l).safe_substitute(deux_eleves))
|
||
|
|
||
|
proc=subprocess.Popen(shlex.split("pdflatex pres_{i}".format(i = int(i/2))))
|
||
|
proc.communicate()
|
||
|
|
||
|
i += 2
|
||
|
|
||
|
os.chdir("..")
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
# -----------------------------
|
||
|
# Reglages pour 'vim'
|
||
|
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
||
|
# cursor: 16 del
|