Feat: écriture du fichier csv

This commit is contained in:
Bertrand Benjamin 2020-10-04 18:49:44 +02:00
parent 1886deb430
commit 77c358b0c1
3 changed files with 23 additions and 4 deletions

View File

@ -1,4 +1,4 @@
nom,email
Nom,email
Star Tice,stice0@jalbum.net
Umberto Dingate,udingate1@tumblr.com
Starlin Crangle,scrangle2@wufoo.com

1 nom Nom email
2 Star Tice stice0@jalbum.net
3 Umberto Dingate udingate1@tumblr.com
4 Starlin Crangle scrangle2@wufoo.com

View File

@ -1,4 +1,4 @@
nom,email
Nom,email
Elle McKintosh,emckintosh0@1und1.de
Ty Megany,tmegany1@reuters.com
Pippa Borrows,pborrows2@a8.net

1 nom Nom email
2 Elle McKintosh emckintosh0@1und1.de
3 Ty Megany tmegany1@reuters.com
4 Pippa Borrows pborrows2@a8.net

View File

@ -5,10 +5,12 @@ import click
from pathlib import Path
import sys
import papermill as pm
import pandas as pd
from datetime import datetime
from .getconfig import config
from .prompts import prompt_exam, prompt_exercise
from ..config import NO_ST_COLUMNS
@click.group()
@ -42,7 +44,8 @@ def exam_dict2element(exam):
"term": exam["term"],
"assessment": exam["name"],
"date": exam["date"].strftime("%d/%m/%Y"),
"exercice": ex["name"],
"exercise": ex["name"],
"question": q["id"],
**q,
}
)
@ -56,7 +59,23 @@ def new_exam():
exam["exercices"] = []
for ex in range(int(exam["ExQty"])):
exam["exercices"].append(prompt_exercise(ex + 1))
print(exam_dict2element(exam))
elements = exam_dict2element(exam)
base_df = pd.DataFrame.from_dict(elements)[NO_ST_COLUMNS.keys()]
base_df.rename(columns=NO_ST_COLUMNS, inplace=True)
students = pd.read_csv(exam["tribe"]["students"])["Nom"]
for student in students:
base_df[student] = ""
dest = (
Path(config["source"])
/ exam["tribe"]["name"]
/ f"{exam['date'].strftime('%y%m%d')}_{exam['name']}.csv"
)
base_df.to_csv(dest, index=False)
print(f"Le fichier note a été enregistré à {dest}")
@cli.command()