Feat: Can use csv to source subjects
This commit is contained in:
parent
f5f9e9193f
commit
21d650101c
@ -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,6 +120,12 @@ def produce_and_compile(options):
|
||||
template = Path(options.template).name
|
||||
logger.debug(f"Template will be {template}")
|
||||
|
||||
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 = []
|
||||
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user