Feat: Can use csv to source subjects

This commit is contained in:
Bertrand Benjamin 2019-10-16 22:45:00 +02:00
parent f5f9e9193f
commit 21d650101c
1 changed files with 23 additions and 1 deletions

View File

@ -5,6 +5,7 @@
Producing then compiling templates
"""
import csv
import os
import logging
import optparse
@ -100,6 +101,13 @@ def pdfjoin(pdf_files, destname, working_dir=".", rm_pdfs=1):
os.system(f"rm {pdf_files_str}")
def extract_student_csv(csv_filename):
""" Extract student list from csv_filename """
with open(csv_filename, "r") as csvfile:
reader = csv.DictReader(csvfile)
return [r["Élève"] for r in reader]
def produce_and_compile(options):
""" Produce and compile subjects
"""
@ -112,7 +120,13 @@ def produce_and_compile(options):
template = Path(options.template).name
logger.debug(f"Template will be {template}")
list_infos = [{"num": f"{i+1:02d}"} for i in range(options.num_subj)]
if options.student_csv:
list_infos = [
{"num": f"{i+1:02d}", "name": s}
for (i, s) in enumerate(extract_student_csv(options.student_csv))
]
else:
list_infos = [{"num": f"{i+1:02d}"} for i in range(options.num_subj)]
tex_files = []
for infos in list_infos:
@ -191,6 +205,14 @@ def main():
default=1,
help="The number of subjects to make",
)
parser.add_option(
"-s",
"--students",
action="store",
type="string",
dest="student_csv",
help="CSV containing list of students names",
)
parser.add_option(
"-d",
"--dirty",