Search function formatting - Check validity membership
This commit is contained in:
parent
f9b62fc805
commit
7dc3d229e9
86
IFPass.py
86
IFPass.py
@ -7,7 +7,7 @@ import configparser
|
||||
import sys
|
||||
import os
|
||||
import re
|
||||
from datetime import date, timedelta
|
||||
from datetime import date, timedelta, datetime
|
||||
import csv
|
||||
import code128
|
||||
import cv2
|
||||
@ -234,11 +234,67 @@ def printcard(cartefilename):
|
||||
subprocess.Popen('"' + AcrobatReader + '"' + ' /h /n /t ' + cartefilename + ' '+ printername, shell=False)
|
||||
|
||||
|
||||
def membersearch():
|
||||
with open(clientsfile, 'r', newline='', encoding='utf-8') as csvfile:
|
||||
reader = csv.reader(csvfile, delimiter=';')
|
||||
csvlist = list(map(tuple, reader))
|
||||
del csvlist[0] # We dele the first line (Prénom, Nom...)
|
||||
research = input('Entrez une partie du nom, prénom, ou numéro de carte (ou flashez) : ').lower()
|
||||
os.system('cls')
|
||||
results = []
|
||||
|
||||
for member in csvlist:
|
||||
resfirstname = member[1].lower()
|
||||
ressurname = member[2].lower()
|
||||
resnumber = member[3]
|
||||
if any(research in data for data in [resfirstname, ressurname, resnumber]):
|
||||
results.append(member)
|
||||
|
||||
if results:
|
||||
if len(results) == 1:
|
||||
member = results[0]
|
||||
else:
|
||||
print('-' * 56)
|
||||
print(f'{"Choix":8} {"Prénom":15} {"Nom":15} {"Numéro de carte":15}')
|
||||
print('-' * 56)
|
||||
for index, result in enumerate(results, start=1):
|
||||
print(f'{index:^8} {result[1]:15} {result[2]:15} {result[3]:^15}')
|
||||
del member
|
||||
while 'The choice is not valid':
|
||||
try:
|
||||
memberchoice = input("De quel membre s'agit il ? (Colonne Choix) : ")
|
||||
member = results[int(memberchoice) - 1]
|
||||
break
|
||||
except (IndexError, ValueError):
|
||||
print(colored('Choix invalide ! Veillez bien à sélectionner le numéro de la colonne "Choix"', 'red', attrs=['bold']))
|
||||
os.system('cls')
|
||||
|
||||
print("Titre : ", colored(member[0], 'green'))
|
||||
print("Prénom : ", colored(member[1], 'green'))
|
||||
print("Nom : ", colored(member[2], 'green'))
|
||||
print("Numéro de carte : ", colored(member[3], 'green'))
|
||||
print("Date d'inscription :", member[4])
|
||||
print("Date d'expiration : ", member[5])
|
||||
dateexp = datetime.strptime(member[5], '%d/%m/%Y').date()
|
||||
diff = (dateexp - date.today()).days
|
||||
if diff > 0:
|
||||
print(colored(f"L'abonnement est encore valable {diff} jours.", 'green', attrs=['bold']))
|
||||
elif diff < 0:
|
||||
print(colored("L'abonnement est expiré depuis {abs(diff)} jours.", 'red', attrs=['bold'])) # abs() to remove minus sign
|
||||
elif diff == 0:
|
||||
print(colored("Il s'agit du dernier jour de l'abonnement, il expirera demain.", 'yellow', attrs=['bold']))
|
||||
|
||||
else:
|
||||
print(colored("Aucun membre n'a été trouvé.", 'red', attrs=['bold']))
|
||||
|
||||
|
||||
while "The program is running":
|
||||
init() # Initialisation of colorama
|
||||
IFPassdir, printername, AcrobatReader, clientsfile, clientsbkpfile, imgdir, pdftemplate, pngtemplate, fonttemplate = initialisation()
|
||||
|
||||
os.system('cls')
|
||||
print('1 - Nouveau membre', '2 - Rechercher un membre', '3 - Quitter', sep='\n')
|
||||
choix = input('Choix : ')
|
||||
IFPassdir, printername, AcrobatReader, clientsfile, clientsbkpfile, imgdir, pdftemplate, pngtemplate, fonttemplate = initialisation()
|
||||
init() # Initialisation of colorama
|
||||
if choix == '1':
|
||||
while "the informations are incorrect": # Loop Filling informations
|
||||
os.system('cls')
|
||||
@ -286,28 +342,7 @@ while "The program is running":
|
||||
printcard(cartefilename)
|
||||
elif choix == '2':
|
||||
os.system('cls')
|
||||
research = input('Entrez le nom, prénom, ou numéro de carte (ou flashez) : ').lower()
|
||||
try:
|
||||
with open(clientsfile, 'r', newline='', encoding='utf-8') as csvfile:
|
||||
results = []
|
||||
for line in csvfile.readlines():
|
||||
resfirstname = line.split(';')[1]
|
||||
resfirstnamemin = resfirstname.lower()
|
||||
ressurname = line.split(';')[2]
|
||||
ressurnamemin = ressurname.lower()
|
||||
resnumber = line.split(';')[3]
|
||||
if any(research in data for data in [resfirstnamemin, ressurnamemin, resnumber]):
|
||||
results.append((resfirstname, ressurname, resnumber))
|
||||
if results:
|
||||
print('Prénom', 'Nom', '"Numéro de carte"')
|
||||
|
||||
for result in results:
|
||||
print(result[0], result[1], result[2])
|
||||
else:
|
||||
print(colored("Aucun membre n'a été trouvé.", 'red', attrs=['bold']))
|
||||
|
||||
except FileNotFoundError:
|
||||
print('Le fichier client est inexistant.')
|
||||
membersearch()
|
||||
|
||||
elif choix == '3':
|
||||
sys.exit()
|
||||
@ -315,3 +350,4 @@ while "The program is running":
|
||||
else:
|
||||
os.system('cls')
|
||||
print(colored('Choix incorrect !', 'red', attrs=['bold']))
|
||||
os.system("pause")
|
||||
|
Loading…
Reference in New Issue
Block a user