diff --git a/bopytex/bopytex.py b/bopytex/bopytex.py index a75d56f..937623d 100755 --- a/bopytex/bopytex.py +++ b/bopytex/bopytex.py @@ -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",