From f72c04ec2d893705cbfd0c0ae1e6698fc0957195 Mon Sep 17 00:00:00 2001 From: "pierre.gauthier" Date: Wed, 19 Feb 2025 16:19:12 +0100 Subject: [PATCH] Feature : ask user to confirm given inputs --- dory_sort_out.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/dory_sort_out.py b/dory_sort_out.py index 95a0699..dc0ff14 100644 --- a/dory_sort_out.py +++ b/dory_sort_out.py @@ -39,6 +39,16 @@ KEYWORDS = { "Plan_de_secteur": FOLDERNAMES[7], } +def confirm_choice(choice) -> bool: + """ + Demande confirmation du choix de l'utilisateur + """ + print(f"vous avez choisi {choice} est-ce correct ?") + answer = int(input("[1] - Oui \n[2] - Non \nReponse : ")) + + return answer == 1 + + def test_date(date_input: str): """teste si la date donnée est valide""" # Pattern pour vérifier qu'il y a bien 8 chiffres, 4pour l'année, 2 pour le mois, 2 pour le jour @@ -235,7 +245,7 @@ def sortout(): # demande si c'est un PLU ou un PLUi tant que l'input ne correspond pas à ce que l'on attend while True: answer = int( - input("[1] - PLU \n[2] - PLUi \nQuel type de dossier est a étudier ? :") + input("[1] - PLU \n[2] - PLUi \nQuel type de dossier est a étudier ? : ") ) if answer > 2 or answer < 1: @@ -243,21 +253,23 @@ def sortout(): # print("\033[A\033[K", end="") #supprime la dernière ligne else: is_plu = answer == 1 - break + if confirm_choice("PLU" if answer == 1 else "PLUi"): + break + # On demande le numero INSEE ou SIREN tant que l'input est invalide while True: print("numero INSEE (Format 5 chiffres): " if is_plu else "numero siren (Format 9 chiffres): ", end="") prefixe = input() - if test_siren_insee(is_plu, prefixe): + if test_siren_insee(is_plu, prefixe) and confirm_choice(prefixe): break # On demande la date d'approbation tant que l'input est invalide while True: print("Date d'approbation (Format AAAAMMJJ): ", end="") suffixe = input() - if test_date(suffixe): + if test_date(suffixe) and confirm_choice(suffixe): break main_path = create_folders(is_plu, prefixe, suffixe)