Feat: Can use csv to source subjects
This commit is contained in:
parent
f5f9e9193f
commit
21d650101c
@ -5,6 +5,7 @@
|
|||||||
Producing then compiling templates
|
Producing then compiling templates
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import csv
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
import optparse
|
import optparse
|
||||||
@ -100,6 +101,13 @@ def pdfjoin(pdf_files, destname, working_dir=".", rm_pdfs=1):
|
|||||||
os.system(f"rm {pdf_files_str}")
|
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):
|
def produce_and_compile(options):
|
||||||
""" Produce and compile subjects
|
""" Produce and compile subjects
|
||||||
"""
|
"""
|
||||||
@ -112,7 +120,13 @@ def produce_and_compile(options):
|
|||||||
template = Path(options.template).name
|
template = Path(options.template).name
|
||||||
logger.debug(f"Template will be {template}")
|
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 = []
|
tex_files = []
|
||||||
for infos in list_infos:
|
for infos in list_infos:
|
||||||
@ -191,6 +205,14 @@ def main():
|
|||||||
default=1,
|
default=1,
|
||||||
help="The number of subjects to make",
|
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(
|
parser.add_option(
|
||||||
"-d",
|
"-d",
|
||||||
"--dirty",
|
"--dirty",
|
||||||
|
Loading…
Reference in New Issue
Block a user