Feature : ask user to confirm given inputs

This commit is contained in:
pierre.gauthier 2025-02-19 16:19:12 +01:00
parent 7381ae0aa4
commit f72c04ec2d

View File

@ -39,6 +39,16 @@ KEYWORDS = {
"Plan_de_secteur": FOLDERNAMES[7], "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): def test_date(date_input: str):
"""teste si la date donnée est valide""" """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 # Pattern pour vérifier qu'il y a bien 8 chiffres, 4pour l'année, 2 pour le mois, 2 pour le jour
@ -243,21 +253,23 @@ def sortout():
# print("\033[A\033[K", end="") #supprime la dernière ligne # print("\033[A\033[K", end="") #supprime la dernière ligne
else: else:
is_plu = answer == 1 is_plu = answer == 1
if confirm_choice("PLU" if answer == 1 else "PLUi"):
break break
# On demande le numero INSEE ou SIREN tant que l'input est invalide # On demande le numero INSEE ou SIREN tant que l'input est invalide
while True: while True:
print("numero INSEE (Format 5 chiffres): " print("numero INSEE (Format 5 chiffres): "
if is_plu else "numero siren (Format 9 chiffres): ", end="") if is_plu else "numero siren (Format 9 chiffres): ", end="")
prefixe = input() prefixe = input()
if test_siren_insee(is_plu, prefixe): if test_siren_insee(is_plu, prefixe) and confirm_choice(prefixe):
break break
# On demande la date d'approbation tant que l'input est invalide # On demande la date d'approbation tant que l'input est invalide
while True: while True:
print("Date d'approbation (Format AAAAMMJJ): ", end="") print("Date d'approbation (Format AAAAMMJJ): ", end="")
suffixe = input() suffixe = input()
if test_date(suffixe): if test_date(suffixe) and confirm_choice(suffixe):
break break
main_path = create_folders(is_plu, prefixe, suffixe) main_path = create_folders(is_plu, prefixe, suffixe)