Feat: classes que je devraient avoir
This commit is contained in:
parent
3512bb8ace
commit
827d7b6511
40
tasks.py
40
tasks.py
@ -12,21 +12,23 @@ import locale
|
||||
locale.setlocale(locale.LC_ALL, "fr_FR.UTF-8")
|
||||
|
||||
TRIBES = [
|
||||
{"name": "Première Technologique", "directory": "1ST"},
|
||||
{"name": "Terminale Technologique", "directory": "TST"},
|
||||
{"name": "Terminale Terminale spé sti2d", "directory": "TST_sti2d"},
|
||||
{"name": "Science numérique et technologique", "directory": "SNT"},
|
||||
{"name": "Terminale L-ES", "directory": "TESL"},
|
||||
{"name": "Terminale sti2d", "directory": "Tsti2d"},
|
||||
]
|
||||
]
|
||||
|
||||
AUTHOR = "Benjamin Bertrand"
|
||||
|
||||
|
||||
def is_tribe(tribe):
|
||||
return tribe in [t["directory"] for t in TRIBES]
|
||||
|
||||
|
||||
def get_sequences(tribe):
|
||||
p = Path(tribe)
|
||||
return [x for x in p.iterdir() if (x.is_dir() and x.name[0:2].isdigit())]
|
||||
|
||||
|
||||
def get_tags(tribe=""):
|
||||
p = Path(tribe)
|
||||
tags = set()
|
||||
@ -36,13 +38,15 @@ def get_tags(tribe=""):
|
||||
line = index.readline()
|
||||
while line:
|
||||
if line.startswith(":tags"):
|
||||
tags.update(line[7:].replace("\n", "").split(', '))
|
||||
tags.update(line[7:].replace("\n", "").split(", "))
|
||||
break
|
||||
line = index.readline()
|
||||
return {t.lower() for t in tags}
|
||||
|
||||
|
||||
def next_weekday(date, day=0):
|
||||
return date + datetime.timedelta(days=(day-date.weekday()+7)%7)
|
||||
return date + datetime.timedelta(days=(day - date.weekday() + 7) % 7)
|
||||
|
||||
|
||||
def sequence_prompt():
|
||||
sequence = {}
|
||||
@ -53,19 +57,24 @@ def sequence_prompt():
|
||||
sequence["date"] = datetime.date.today()
|
||||
|
||||
tribes = WordCompleter([t["directory"] for t in TRIBES])
|
||||
sequence["tribe"] = prompt("Classe: ", completer=tribes, validator=Validator.from_callable(is_tribe))
|
||||
sequence["tribe"] = prompt(
|
||||
"Classe: ", completer=tribes, validator=Validator.from_callable(is_tribe)
|
||||
)
|
||||
|
||||
sequences = get_sequences(sequence["tribe"])
|
||||
print("Séquences trouvées:\n\t" + '\n\t'.join(sorted([s.name for s in sequences])))
|
||||
print("Séquences trouvées:\n\t" + "\n\t".join(sorted([s.name for s in sequences])))
|
||||
sequence["num"] = len(sequences) + 1
|
||||
sequence["title"] = prompt(f"Nom de la séquence (n°{sequence['num']}): ")
|
||||
|
||||
known_tags = get_tags()
|
||||
sequence["tags"] = prompt("Tags (séparés par une virgule): ", completer=WordCompleter(known_tags))
|
||||
sequence["tags"] = prompt(
|
||||
"Tags (séparés par une virgule): ", completer=WordCompleter(known_tags)
|
||||
)
|
||||
|
||||
sequence["summary"] = prompt("Résumé: ")
|
||||
return sequence
|
||||
|
||||
|
||||
def import_skel(dest, datas, skel="sequence", skel_path="./tools/skeleton"):
|
||||
d = Path(dest)
|
||||
d.mkdir()
|
||||
@ -87,15 +96,18 @@ def import_skel(dest, datas, skel="sequence", skel_path="./tools/skeleton"):
|
||||
|
||||
output_text = template.render(**datas)
|
||||
|
||||
with open(d/filename, "w") as f:
|
||||
with open(d / filename, "w") as f:
|
||||
f.write(output_text)
|
||||
print(f"Importation de {filename} - OK")
|
||||
|
||||
|
||||
@task
|
||||
def sequence(c):
|
||||
sequence = sequence_prompt()
|
||||
|
||||
dest = unidecode(("{tribe}/{num:0>2}_{title}/".format(**sequence)).replace(" ", "_"))
|
||||
dest = unidecode(
|
||||
("{tribe}/{num:0>2}_{title}/".format(**sequence)).replace(" ", "_")
|
||||
)
|
||||
dest = Path(dest)
|
||||
|
||||
seq_summary = """\
|
||||
@ -106,12 +118,14 @@ def sequence(c):
|
||||
Tags: {tags}
|
||||
Sommaire: {summary}
|
||||
Dossier: {dest}
|
||||
""".format(dest=dest, **sequence)
|
||||
""".format(
|
||||
dest=dest, **sequence
|
||||
)
|
||||
print(seq_summary)
|
||||
|
||||
validate = prompt("C'est ok? ")
|
||||
if validate.lower() in ["o", "y", ""]:
|
||||
sequence["title_under"] = '#'*len(sequence["title"])
|
||||
sequence["title_under"] = "#" * len(sequence["title"])
|
||||
import_skel(dest, sequence, "sequence")
|
||||
else:
|
||||
print("Tant pis. Ya plus qu'à recommencer.")
|
||||
|
Loading…
Reference in New Issue
Block a user