From d5c4ee5997461ce6b618fcfb64dc3b21275369f3 Mon Sep 17 00:00:00 2001 From: Jordan ERNST Date: Wed, 20 Feb 2019 17:17:45 +0100 Subject: [PATCH 01/10] Name now on to lines. --- IFPass.py | 62 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/IFPass.py b/IFPass.py index c3a665f..5f08930 100644 --- a/IFPass.py +++ b/IFPass.py @@ -112,11 +112,11 @@ def get_fullname(): docteur = yes_or_no('Est-ce un Docteur ?') if docteur: titre = 'Dr.' - fullname = titre + ' ' + surname + ' ' + firstname + titrename = titre + ' ' + surname else: titre = '' - fullname = surname + ' ' + firstname - return titre, firstname, surname, fullname + titrename = surname + return titre, firstname, surname, titrename def yes_or_no(question): @@ -137,7 +137,6 @@ def getclientID(): else: clientID = str(int(lastID) + 1).zfill(10) - writeindb(clientID) return clientID @@ -228,12 +227,13 @@ def fillcard(barcode): draw = ImageDraw.Draw(im) # Name embedding : - font = ImageFont.truetype(fonttemplate, 45) - draw.text((401, 310), fullname, fill=(0, 0, 0), font=font) + font = ImageFont.truetype(fonttemplate, 40) + draw.text((401, 296), titrename, fill=(0, 0, 0), font=font) + draw.text((401, 334), firstname, fill=(0, 0, 0), font=font) # Date embedding : font = ImageFont.truetype(fonttemplate, 30) - draw.text((401, 390), dateexp, fill=(0, 0, 0), font=font) + draw.text((401, 400), dateexp, fill=(0, 0, 0), font=font) # ID embedding : font = ImageFont.truetype('arial.ttf', 30) @@ -248,6 +248,7 @@ def fillcard(barcode): # Create PDF : im = im.convert("RGB") im.save(imgdir + clientID + '_Front.pdf', 'PDF', resolution=299.0, quality=98) + writeindb(clientID) print(colored('[OK]', 'green')) @@ -312,27 +313,41 @@ def membersearch(): 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'])) + while 'Choix incorect': + 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'])) + + print('\n1 - Modifier', "2 - Renouveller l'abonnement", '3 - Menu principal', sep='\n') + choix = input('Choix : ') + if choix == '1': + print(1) + elif choix == '2': + print(2) + elif choix == '3': + return + else: + os.system('cls') + print(colored('Choix incorrect !\n', 'red', attrs=['bold'])) else: print(colored("Aucun membre n'a été trouvé.", 'red', attrs=['bold'])) + os.system("pause") def main(): - global titre, firstname, surname, fullname, dateinsc, dateexp, clientID, clientsfile, IFPassDBdir, clientsfile, imgdir, clientsbkpfile, templatesdir, pngtemplate, fonttemplate, picture, pdftemplate, printername, AcrobatReader + global titre, firstname, surname, titrename, dateinsc, dateexp, clientID, clientsfile, IFPassDBdir, clientsfile, imgdir, clientsbkpfile, templatesdir, pngtemplate, fonttemplate, picture, pdftemplate, printername, AcrobatReader while "The program is running": init() # Initialisation of colorama IFPassDBdir, printername, AcrobatReader, clientsfile, clientsbkpfile, imgdir, templatesdir, pdftemplate, pngtemplate, fonttemplate = initialisation() @@ -350,7 +365,7 @@ def main(): if choix == '1': while "the informations are incorrect": # Loop Filling informations os.system('cls') - titre, firstname, surname, fullname = get_fullname() + titre, firstname, surname, titrename = get_fullname() dateinsc = date.today() dateexp = dateinsc + timedelta(days=365) @@ -391,7 +406,6 @@ def main(): elif choix == '2': os.system('cls') membersearch() - os.system("pause") elif choix == '3': sys.exit() From 0ce5ed334c600a24477596ffdb558073313a964d Mon Sep 17 00:00:00 2001 From: Jordan ERNST Date: Wed, 27 Feb 2019 12:34:36 +0100 Subject: [PATCH 02/10] Code reformatting : function newmember() --- IFPass.py | 152 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 95 insertions(+), 57 deletions(-) diff --git a/IFPass.py b/IFPass.py index 5f08930..8fd442e 100644 --- a/IFPass.py +++ b/IFPass.py @@ -201,7 +201,7 @@ def getpic(): sys.exit() -def writeindb(clientID): +def writeindb(titre, firstname, surname, clientID, dateinsc, dateexp): print("Ajout dans la base de données... ", end="") with open(clientsfile, 'a', newline='', encoding='utf-8') as csvfile: writer = csv.writer(csvfile, delimiter=';') @@ -213,7 +213,7 @@ def bkpdb(): copyfile(clientsfile, clientsbkpfile) -def fillcard(barcode): +def fillcard(clientID, titrename, firstname, dateexp, barcode): print("Création de la carte avec les informations...", end='') try: im = Image.open(pngtemplate) @@ -248,12 +248,11 @@ def fillcard(barcode): # Create PDF : im = im.convert("RGB") im.save(imgdir + clientID + '_Front.pdf', 'PDF', resolution=299.0, quality=98) - writeindb(clientID) print(colored('[OK]', 'green')) -def mergepdf(): +def mergepdf(clientID): cartefilename = os.path.join(imgdir, clientID + '.pdf') output = PdfFileWriter() @@ -278,6 +277,49 @@ def printcard(cartefilename): subprocess.Popen('"' + AcrobatReader + '"' + ' /h /n /t ' + cartefilename + ' ' + printername, shell=False) +def newmember(): + while "the informations are incorrect": # Loop Filling informations + os.system('cls') + titre, firstname, surname, titrename = get_fullname() + dateinsc = date.today() + dateexp = dateinsc + timedelta(days=365) + + dateinsc = dateinsc.strftime('%d/%m/%Y') + dateexp = dateexp.strftime('%d/%m/%Y') + changeexp = yes_or_no("Voulez-vous choisir la date d'expiration ?") + if changeexp: + while True: + dateexp = input("Quelle date d'expiration voulez-vous mettre (Format : JJ/MM/AAAA)? : ") + match = re.fullmatch(r'^(0[1-9]|1[0-9]|2[0-9]|3[0-1])/(0[1-9]|1[0-2])/([0-9]){4}$', dateexp) + if match: + break + else: + print('Mauvais format ! JJ/MM/AAAA, exemple : 01/08/2042') + + os.system('cls') + print("Titre : ", colored(titre, 'green')) + print("Prénom : ", colored(firstname, 'green')) + print("Nom : ", colored(surname, 'green')) + print("Date d'inscription :", colored(dateinsc, 'green')) + print("Date d'expiration : ", colored(dateexp, 'green')) + correct = yes_or_no("Ces informations sont elles correctes ?") + + if correct: + os.system('cls') + if version != 'devnocam': + global picture + picture = getpic() + clientID = getclientID() + barcode = barcode_gen(clientID) + fillcard(clientID, titrename, firstname, dateexp, barcode) + cartefilename = mergepdf(clientID) + if version not in ('dev', 'devnocam'): + bkpdb() + printcard(cartefilename) + writeindb(titre, firstname, surname, clientID, dateinsc, dateexp) + break + + def membersearch(): with open(clientsfile, 'r', newline='', encoding='utf-8') as csvfile: reader = csv.reader(csvfile, delimiter=';') @@ -329,25 +371,59 @@ def membersearch(): elif diff == 0: print(colored("Il s'agit du dernier jour de l'abonnement, il expirera demain.", 'yellow', attrs=['bold'])) - print('\n1 - Modifier', "2 - Renouveller l'abonnement", '3 - Menu principal', sep='\n') + print('\n1 - Modifier', "2 - Renouveller l'abonnement", '3 - Imprimer la carte', '0 - Menu principal', sep='\n') choix = input('Choix : ') - if choix == '1': - print(1) - elif choix == '2': - print(2) - elif choix == '3': - return - else: - os.system('cls') - print(colored('Choix incorrect !\n', 'red', attrs=['bold'])) - + memberdo(choix, member) else: print(colored("Aucun membre n'a été trouvé.", 'red', attrs=['bold'])) os.system("pause") +def memberdo(choix, member): + titre = member[0] + firstname = member[1] + os.system('cls') + if choix == '1': # Edit member + while "the informations are incorrect": # Loop Filling informations + titre, firstname, surname, titrename = get_fullname() + + os.system('cls') + print("Titre : ", colored(titre, 'green')) + print("Prénom : ", colored(firstname, 'green')) + print("Nom : ", colored(surname, 'green')) + + correct = yes_or_no("Ces informations sont elles correctes ?") + + if correct: + newpic = yes_or_no("Voulez-vous prendre une nouvelle photo ?") + if newpic: + os.system('cls') + if version != 'devnocam': + global picture + picture = getpic() + clientID = member[3] + barcode = barcode_gen(clientID) + fillcard(barcode) + cartefilename = mergepdf() + if version not in ('dev', 'devnocam'): + bkpdb() + printcard(cartefilename) + break + + elif choix == '2': # Renew subscription + print(2) + elif choix == '3': # Print card + print('Print card') + elif choix == '0': # Menu + return + else: + os.system('cls') + print(colored('Choix incorrect !\n', 'red', attrs=['bold'])) + + def main(): - global titre, firstname, surname, titrename, dateinsc, dateexp, clientID, clientsfile, IFPassDBdir, clientsfile, imgdir, clientsbkpfile, templatesdir, pngtemplate, fonttemplate, picture, pdftemplate, printername, AcrobatReader + # global titre, firstname, surname, titrename, dateinsc, dateexp, clientID, clientsfile, IFPassDBdir, clientsfile, imgdir, clientsbkpfile, templatesdir, pngtemplate, fonttemplate, picture, pdftemplate, printername, AcrobatReader + global IFPassDBdir, clientsfile, imgdir, clientsbkpfile, templatesdir, pngtemplate, fonttemplate, pdftemplate, printername, AcrobatReader while "The program is running": init() # Initialisation of colorama IFPassDBdir, printername, AcrobatReader, clientsfile, clientsbkpfile, imgdir, templatesdir, pdftemplate, pngtemplate, fonttemplate = initialisation() @@ -360,54 +436,16 @@ def main(): print(colored("\nATTENTION : Il s'agit d'une version en cours de développement, potentiellement instable !", 'red')) print("\nLe programme IFPass à été écrit par Jordan ERNST Q1 2018 pour l'Institut Français en Hongrie.") print('Pour toute question, problème ou requête contactez-moi à pro.ernst@gmail.com.\n') - print('1 - Nouveau membre', '2 - Rechercher un membre', '3 - Quitter', sep='\n') + print('1 - Nouveau membre', '2 - Rechercher un membre', '0 - Quitter', sep='\n') choix = input('Choix : ') if choix == '1': - while "the informations are incorrect": # Loop Filling informations - os.system('cls') - titre, firstname, surname, titrename = get_fullname() - dateinsc = date.today() - dateexp = dateinsc + timedelta(days=365) - - dateinsc = dateinsc.strftime('%d/%m/%Y') - dateexp = dateexp.strftime('%d/%m/%Y') - changeexp = yes_or_no("Voulez-vous choisir la date d'expiration ?") - if changeexp: - while True: - dateexp = input("Quelle date d'expiration voulez-vous mettre (Format : JJ/MM/AAAA)? : ") - match = re.fullmatch(r'^(0[1-9]|1[0-9]|2[0-9]|3[0-1])/(0[1-9]|1[0-2])/([0-9]){4}$', dateexp) - if match: - break - else: - print('Mauvais format ! JJ/MM/AAAA, exemple : 01/08/2042') - - os.system('cls') - print("Titre : ", colored(titre, 'green')) - print("Prénom : ", colored(firstname, 'green')) - print("Nom : ", colored(surname, 'green')) - print("Date d'inscription :", colored(dateinsc, 'green')) - print("Date d'expiration : ", colored(dateexp, 'green')) - correct = yes_or_no("Ces informations sont elles correctes ?") - - if correct: - os.system('cls') - if version != 'devnocam': - global picture - picture = getpic() - clientID = getclientID() - barcode = barcode_gen(clientID) - fillcard(barcode) - cartefilename = mergepdf() - if version not in ('dev', 'devnocam'): - bkpdb() - printcard(cartefilename) - break + newmember() elif choix == '2': os.system('cls') membersearch() - elif choix == '3': + elif choix == '0': sys.exit() else: From d651a4973a73477f63abb5db8d326322dcaf1ea7 Mon Sep 17 00:00:00 2001 From: Jordan ERNST Date: Thu, 28 Feb 2019 09:25:06 +0100 Subject: [PATCH 03/10] Edit member ongoing --- IFPass.py | 66 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 24 deletions(-) diff --git a/IFPass.py b/IFPass.py index 8fd442e..4d79dd7 100644 --- a/IFPass.py +++ b/IFPass.py @@ -85,14 +85,20 @@ def initialisation(): return IFPassDBdir, printername, AcrobatReader, clientsfile, clientsbkpfile, imgdir, templatesdir, pdftemplate, pngtemplate, fonttemplate -def get_fullname(): - while "Empty firstname": - firstname = input("Prénom : ").strip() - if len(firstname) == 0: - os.system('cls') - print(colored("\nLe Prénom ne peut pas être vide.", 'red')) - else: - break +def get_fullname(**kwargs): # **kwargs => Optionnal arguments + if 'firstname' in kwargs: + firstname = kwargs['firstname'] + newfirstname = input("Prénom (" + firstname + "): ").strip() + if len(newfirstname) != 0: + firstname = newfirstname + else: + while "Empty firstname": + firstname = input("Prénom : ").strip() + if len(firstname) == 0: + os.system('cls') + print(colored("\nLe Prénom ne peut pas être vide.", 'red')) + else: + break firstname = firstname[0].upper() + firstname[1:].lower() if '-' in firstname: pos = firstname.find("-") @@ -102,13 +108,20 @@ def get_fullname(): pos = firstname.find(" ") firstname = firstname[:pos + 1] + firstname[pos + 1].upper() + \ firstname[pos + 2:] # Check if compound name - while "Empty surname": - surname = input("Nom : ").upper().strip() - if len(surname) == 0: - os.system('cls') - print(colored("\nLe Nom ne peut pas être vide.", 'red')) - else: - break + + if 'surname' in kwargs: + surname = kwargs['surname'] + newsurname = input("Prénom (" + surname + "): ").strip() + if len(newsurname) != 0: + surname = newsurname + else: + while "Empty surname": + surname = input("Nom : ").upper().strip() + if len(surname) == 0: + os.system('cls') + print(colored("\nLe Nom ne peut pas être vide.", 'red')) + else: + break docteur = yes_or_no('Est-ce un Docteur ?') if docteur: titre = 'Dr.' @@ -213,7 +226,7 @@ def bkpdb(): copyfile(clientsfile, clientsbkpfile) -def fillcard(clientID, titrename, firstname, dateexp, barcode): +def fillcard(clientID, titrename, firstname, dateexp, barcode, picture): print("Création de la carte avec les informations...", end='') try: im = Image.open(pngtemplate) @@ -307,11 +320,10 @@ def newmember(): if correct: os.system('cls') if version != 'devnocam': - global picture picture = getpic() clientID = getclientID() barcode = barcode_gen(clientID) - fillcard(clientID, titrename, firstname, dateexp, barcode) + fillcard(clientID, titrename, firstname, dateexp, barcode, picture) cartefilename = mergepdf(clientID) if version not in ('dev', 'devnocam'): bkpdb() @@ -382,10 +394,14 @@ def membersearch(): def memberdo(choix, member): titre = member[0] firstname = member[1] + surname = member[2] + clientID = member[3] + dateinsc = member[4] + dateexp = member[5] os.system('cls') if choix == '1': # Edit member while "the informations are incorrect": # Loop Filling informations - titre, firstname, surname, titrename = get_fullname() + titre, firstname, surname, titrename = get_fullname(titre=titre, firstname=firstname, surname=surname) os.system('cls') print("Titre : ", colored(titre, 'green')) @@ -395,20 +411,23 @@ def memberdo(choix, member): correct = yes_or_no("Ces informations sont elles correctes ?") if correct: - newpic = yes_or_no("Voulez-vous prendre une nouvelle photo ?") - if newpic: + wantnewpic = yes_or_no("Voulez-vous prendre une nouvelle photo ?") + if wantnewpic: os.system('cls') if version != 'devnocam': - global picture picture = getpic() clientID = member[3] barcode = barcode_gen(clientID) - fillcard(barcode) + fillcard(clientID, titrename, firstname, dateexp, barcode, picture) cartefilename = mergepdf() if version not in ('dev', 'devnocam'): bkpdb() printcard(cartefilename) + writeindb(titre, firstname, surname, clientID, dateinsc, dateexp) break + else: + # We crop pic from the previous card + pass elif choix == '2': # Renew subscription print(2) @@ -422,7 +441,6 @@ def memberdo(choix, member): def main(): - # global titre, firstname, surname, titrename, dateinsc, dateexp, clientID, clientsfile, IFPassDBdir, clientsfile, imgdir, clientsbkpfile, templatesdir, pngtemplate, fonttemplate, picture, pdftemplate, printername, AcrobatReader global IFPassDBdir, clientsfile, imgdir, clientsbkpfile, templatesdir, pngtemplate, fonttemplate, pdftemplate, printername, AcrobatReader while "The program is running": init() # Initialisation of colorama From 3dbb48d7fcf554d7a2bc39aaf7329a96ad2819d3 Mon Sep 17 00:00:00 2001 From: Jordan ERNST Date: Thu, 28 Feb 2019 15:50:07 +0100 Subject: [PATCH 04/10] Added modif line in writeindb() for member modification --- IFPass.py | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/IFPass.py b/IFPass.py index 4d79dd7..cfdd26d 100644 --- a/IFPass.py +++ b/IFPass.py @@ -214,12 +214,35 @@ def getpic(): sys.exit() -def writeindb(titre, firstname, surname, clientID, dateinsc, dateexp): - print("Ajout dans la base de données... ", end="") - with open(clientsfile, 'a', newline='', encoding='utf-8') as csvfile: - writer = csv.writer(csvfile, delimiter=';') - writer.writerow([titre, firstname, surname, clientID, dateinsc, dateexp]) - print(colored('[OK]', 'green')) +def writeindb(titre, firstname, surname, clientID, dateinsc, dateexp, new): + if new is True: + print("Ajout dans la base de données... ", end="") + with open(clientsfile, 'a', newline='', encoding='utf-8') as csvfile: + writer = csv.writer(csvfile, delimiter=';') + writer.writerow([titre, firstname, surname, clientID, dateinsc, dateexp]) + print(colored('[OK]', 'green')) + elif new is False: + print("Modification de la base de données... ", end="") + with open(clientsfile, 'r+', newline='', encoding='utf-8') as csvfile: + content = csvfile.readlines() + for index, member in enumerate(content): + member = member.split(';') + if member[3] == clientID: + tochange = index + break + content.pop(tochange) + changewith = ";".join([titre, firstname, surname, clientID, dateinsc, dateexp]) + '\n' + content.insert(tochange, changewith) + content = "".join(content) + csvfile.truncate(0) + csvfile.write(content) + + reader = csv.reader(csvfile, delimiter=';') + writer = csv.writer(csvfile, delimiter=';') + for index, member in enumerate(reader): + if member[3] == clientID: + + print(colored('[OK]', 'green')) def bkpdb(): @@ -328,7 +351,7 @@ def newmember(): if version not in ('dev', 'devnocam'): bkpdb() printcard(cartefilename) - writeindb(titre, firstname, surname, clientID, dateinsc, dateexp) + writeindb(titre, firstname, surname, clientID, dateinsc, dateexp, new=True) break @@ -423,7 +446,7 @@ def memberdo(choix, member): if version not in ('dev', 'devnocam'): bkpdb() printcard(cartefilename) - writeindb(titre, firstname, surname, clientID, dateinsc, dateexp) + writeindb(titre, firstname, surname, clientID, dateinsc, dateexp, new=False) break else: # We crop pic from the previous card From a500e2267884b020317aad89313a0c43f1a520c6 Mon Sep 17 00:00:00 2001 From: Jordan ERNST Date: Thu, 28 Feb 2019 16:31:11 +0100 Subject: [PATCH 05/10] Corrections --- IFPass.py | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/IFPass.py b/IFPass.py index cfdd26d..1ae0f1c 100644 --- a/IFPass.py +++ b/IFPass.py @@ -237,12 +237,7 @@ def writeindb(titre, firstname, surname, clientID, dateinsc, dateexp, new): csvfile.truncate(0) csvfile.write(content) - reader = csv.reader(csvfile, delimiter=';') - writer = csv.writer(csvfile, delimiter=';') - for index, member in enumerate(reader): - if member[3] == clientID: - - print(colored('[OK]', 'green')) + print(colored('[OK]', 'green')) def bkpdb(): @@ -351,7 +346,7 @@ def newmember(): if version not in ('dev', 'devnocam'): bkpdb() printcard(cartefilename) - writeindb(titre, firstname, surname, clientID, dateinsc, dateexp, new=True) + writeindb(titre, firstname, surname, clientID, dateinsc, dateexp, new=True) break @@ -421,6 +416,7 @@ def memberdo(choix, member): clientID = member[3] dateinsc = member[4] dateexp = member[5] + os.system('cls') if choix == '1': # Edit member while "the informations are incorrect": # Loop Filling informations @@ -439,19 +435,19 @@ def memberdo(choix, member): os.system('cls') if version != 'devnocam': picture = getpic() - clientID = member[3] - barcode = barcode_gen(clientID) - fillcard(clientID, titrename, firstname, dateexp, barcode, picture) - cartefilename = mergepdf() - if version not in ('dev', 'devnocam'): - bkpdb() - printcard(cartefilename) - writeindb(titre, firstname, surname, clientID, dateinsc, dateexp, new=False) - break else: # We crop pic from the previous card pass + barcode = barcode_gen(clientID) + fillcard(clientID, titrename, firstname, dateexp, barcode, picture) + cartefilename = mergepdf() + if version not in ('dev', 'devnocam'): + bkpdb() + printcard(cartefilename) + writeindb(titre, firstname, surname, clientID, dateinsc, dateexp, new=False) + break + elif choix == '2': # Renew subscription print(2) elif choix == '3': # Print card From f3f86c43a6831f1e15d497e6ed7377e7c18a6329 Mon Sep 17 00:00:00 2001 From: Jordan ERNST Date: Fri, 1 Mar 2019 14:52:13 +0100 Subject: [PATCH 06/10] Member edit implementation done. Recover previous picture added. --- IFPass.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/IFPass.py b/IFPass.py index 1ae0f1c..4c3a437 100644 --- a/IFPass.py +++ b/IFPass.py @@ -15,6 +15,7 @@ from pywinauto.findwindows import find_window from pywinauto.win32functions import SetForegroundWindow from PIL import Image, ImageDraw, ImageFont from PyPDF2 import PdfFileReader, PdfFileWriter +import fitz import subprocess from shutil import copyfile, move from pyfiglet import Figlet @@ -437,7 +438,13 @@ def memberdo(choix, member): picture = getpic() else: # We crop pic from the previous card - pass + pdf = fitz.open('PDF.pdf') + page = pdf.loadPage(0) + mat = fitz.Matrix(4.165, 4.165) # To obtain good resolution + pix = page.getPixmap(matrix=mat) + + pageimg = Image.frombytes("RGBA", [pix.width, pix.height], pix.samples) + picture = pageimg.crop((47, 49, 343, 378)) barcode = barcode_gen(clientID) fillcard(clientID, titrename, firstname, dateexp, barcode, picture) From a1beec5cd16e858a8a225f1c963e29b325e216e9 Mon Sep 17 00:00:00 2001 From: Jordan ERNST Date: Fri, 1 Mar 2019 15:19:40 +0100 Subject: [PATCH 07/10] Fix various bugs --- IFPass.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/IFPass.py b/IFPass.py index 4c3a437..53e5c08 100644 --- a/IFPass.py +++ b/IFPass.py @@ -15,7 +15,7 @@ from pywinauto.findwindows import find_window from pywinauto.win32functions import SetForegroundWindow from PIL import Image, ImageDraw, ImageFont from PyPDF2 import PdfFileReader, PdfFileWriter -import fitz +import fitz # = PyMuPDF : To convert pdf to png import subprocess from shutil import copyfile, move from pyfiglet import Figlet @@ -117,12 +117,13 @@ def get_fullname(**kwargs): # **kwargs => Optionnal arguments surname = newsurname else: while "Empty surname": - surname = input("Nom : ").upper().strip() + surname = input("Nom : ").strip() if len(surname) == 0: os.system('cls') print(colored("\nLe Nom ne peut pas être vide.", 'red')) else: break + surname = surname.upper() docteur = yes_or_no('Est-ce un Docteur ?') if docteur: titre = 'Dr.' @@ -384,7 +385,7 @@ def membersearch(): 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') + os.system('cls') while 'Choix incorect': print("Titre : ", colored(member[0], 'green')) @@ -438,7 +439,8 @@ def memberdo(choix, member): picture = getpic() else: # We crop pic from the previous card - pdf = fitz.open('PDF.pdf') + cartefilename = os.path.join(imgdir, clientID + '.pdf') + pdf = fitz.open(cartefilename) page = pdf.loadPage(0) mat = fitz.Matrix(4.165, 4.165) # To obtain good resolution pix = page.getPixmap(matrix=mat) @@ -448,7 +450,7 @@ def memberdo(choix, member): barcode = barcode_gen(clientID) fillcard(clientID, titrename, firstname, dateexp, barcode, picture) - cartefilename = mergepdf() + cartefilename = mergepdf(clientID) if version not in ('dev', 'devnocam'): bkpdb() printcard(cartefilename) From 5d76b1f58481c3679f958bc2988f35c858addbb0 Mon Sep 17 00:00:00 2001 From: Jordan ERNST Date: Mon, 4 Mar 2019 17:36:01 +0100 Subject: [PATCH 08/10] Renew membership implementation + Multiple fixes. --- IFPass.py | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/IFPass.py b/IFPass.py index 53e5c08..90c65ac 100644 --- a/IFPass.py +++ b/IFPass.py @@ -112,7 +112,7 @@ def get_fullname(**kwargs): # **kwargs => Optionnal arguments if 'surname' in kwargs: surname = kwargs['surname'] - newsurname = input("Prénom (" + surname + "): ").strip() + newsurname = input("Nom (" + surname + "): ").strip() if len(newsurname) != 0: surname = newsurname else: @@ -224,7 +224,7 @@ def writeindb(titre, firstname, surname, clientID, dateinsc, dateexp, new): writer.writerow([titre, firstname, surname, clientID, dateinsc, dateexp]) print(colored('[OK]', 'green')) elif new is False: - print("Modification de la base de données... ", end="") + print("Modification de la base de données... ", end="") with open(clientsfile, 'r+', newline='', encoding='utf-8') as csvfile: content = csvfile.readlines() for index, member in enumerate(content): @@ -236,6 +236,7 @@ def writeindb(titre, firstname, surname, clientID, dateinsc, dateexp, new): changewith = ";".join([titre, firstname, surname, clientID, dateinsc, dateexp]) + '\n' content.insert(tochange, changewith) content = "".join(content) + csvfile.seek(0) csvfile.truncate(0) csvfile.write(content) @@ -355,7 +356,7 @@ def newmember(): def membersearch(): with open(clientsfile, 'r', newline='', encoding='utf-8') as csvfile: reader = csv.reader(csvfile, delimiter=';') - csvlist = list(map(tuple, reader)) + csvlist = list(map(list, 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') @@ -405,7 +406,13 @@ def membersearch(): print('\n1 - Modifier', "2 - Renouveller l'abonnement", '3 - Imprimer la carte', '0 - Menu principal', sep='\n') choix = input('Choix : ') - memberdo(choix, member) + if choix == '0': + os.system('cls') + return + # We update values with new (edited) values : + newtitre, newfirstname, newsurname, newdateexp = memberdo(choix, member) + member[0], member[1], member[2], member[5] = newtitre, newfirstname, newsurname, newdateexp + else: print(colored("Aucun membre n'a été trouvé.", 'red', attrs=['bold'])) os.system("pause") @@ -424,15 +431,16 @@ def memberdo(choix, member): while "the informations are incorrect": # Loop Filling informations titre, firstname, surname, titrename = get_fullname(titre=titre, firstname=firstname, surname=surname) - os.system('cls') print("Titre : ", colored(titre, 'green')) print("Prénom : ", colored(firstname, 'green')) print("Nom : ", colored(surname, 'green')) correct = yes_or_no("Ces informations sont elles correctes ?") + os.system('cls') if correct: wantnewpic = yes_or_no("Voulez-vous prendre une nouvelle photo ?") + os.system('cls') if wantnewpic: os.system('cls') if version != 'devnocam': @@ -455,17 +463,28 @@ def memberdo(choix, member): bkpdb() printcard(cartefilename) writeindb(titre, firstname, surname, clientID, dateinsc, dateexp, new=False) + os.system('cls') break elif choix == '2': # Renew subscription - print(2) + dateexp = datetime.strptime(dateexp, '%d/%m/%Y').date() + diff = (dateexp - date.today()).days + if diff >= 0: + dateexp = dateexp + timedelta(days=365) + elif diff < 0: + dateexp = date.today() + timedelta(days=365) + dateexp = dateexp.strftime('%d/%m/%Y') + if version not in ('dev', 'devnocam'): + bkpdb() + printcard(cartefilename) + writeindb(titre, firstname, surname, clientID, dateinsc, dateexp, new=False) + print(colored("La date d'expiration a bien été mise à jour !\n", 'blue', attrs=['bold'])) + elif choix == '3': # Print card print('Print card') - elif choix == '0': # Menu - return else: - os.system('cls') print(colored('Choix incorrect !\n', 'red', attrs=['bold'])) + return titre, firstname, surname, dateexp def main(): From 9ab362fd29af53f5206e9a412cf3a8b1a8c03f32 Mon Sep 17 00:00:00 2001 From: Jordan ERNST Date: Tue, 5 Mar 2019 09:33:27 +0100 Subject: [PATCH 09/10] Bugs corrections --- IFPass.py | 108 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 70 insertions(+), 38 deletions(-) diff --git a/IFPass.py b/IFPass.py index 90c65ac..73690a4 100644 --- a/IFPass.py +++ b/IFPass.py @@ -428,43 +428,7 @@ def memberdo(choix, member): os.system('cls') if choix == '1': # Edit member - while "the informations are incorrect": # Loop Filling informations - titre, firstname, surname, titrename = get_fullname(titre=titre, firstname=firstname, surname=surname) - - print("Titre : ", colored(titre, 'green')) - print("Prénom : ", colored(firstname, 'green')) - print("Nom : ", colored(surname, 'green')) - - correct = yes_or_no("Ces informations sont elles correctes ?") - os.system('cls') - - if correct: - wantnewpic = yes_or_no("Voulez-vous prendre une nouvelle photo ?") - os.system('cls') - if wantnewpic: - os.system('cls') - if version != 'devnocam': - picture = getpic() - else: - # We crop pic from the previous card - cartefilename = os.path.join(imgdir, clientID + '.pdf') - pdf = fitz.open(cartefilename) - page = pdf.loadPage(0) - mat = fitz.Matrix(4.165, 4.165) # To obtain good resolution - pix = page.getPixmap(matrix=mat) - - pageimg = Image.frombytes("RGBA", [pix.width, pix.height], pix.samples) - picture = pageimg.crop((47, 49, 343, 378)) - - barcode = barcode_gen(clientID) - fillcard(clientID, titrename, firstname, dateexp, barcode, picture) - cartefilename = mergepdf(clientID) - if version not in ('dev', 'devnocam'): - bkpdb() - printcard(cartefilename) - writeindb(titre, firstname, surname, clientID, dateinsc, dateexp, new=False) - os.system('cls') - break + titre, firstname, surname, dateexp = memberedit(titre, firstname, surname, clientID, dateinsc, dateexp) elif choix == '2': # Renew subscription dateexp = datetime.strptime(dateexp, '%d/%m/%Y').date() @@ -474,19 +438,87 @@ def memberdo(choix, member): elif diff < 0: dateexp = date.today() + timedelta(days=365) dateexp = dateexp.strftime('%d/%m/%Y') + + if titre == 'Dr.': + titrename = titre + ' ' + surname + else: + titrename = surname + + wantnewpic = yes_or_no("Voulez-vous prendre une nouvelle photo ?") + os.system('cls') + if wantnewpic: + os.system('cls') + if version != 'devnocam': + picture = getpic() + else: + # We crop pic from the previous card + cartefilename = os.path.join(imgdir, clientID + '.pdf') + pdf = fitz.open(cartefilename) + page = pdf.loadPage(0) + mat = fitz.Matrix(4.165, 4.165) # To obtain good resolution + pix = page.getPixmap(matrix=mat) + pageimg = Image.frombytes("RGBA", [pix.width, pix.height], pix.samples) + picture = pageimg.crop((47, 49, 343, 378)) + + barcode = barcode_gen(clientID) + fillcard(clientID, titrename, firstname, dateexp, barcode, picture) + cartefilename = mergepdf(clientID) + if version not in ('dev', 'devnocam'): bkpdb() printcard(cartefilename) writeindb(titre, firstname, surname, clientID, dateinsc, dateexp, new=False) + os.system('cls') print(colored("La date d'expiration a bien été mise à jour !\n", 'blue', attrs=['bold'])) elif choix == '3': # Print card - print('Print card') + printcard(cartefilename) else: print(colored('Choix incorrect !\n', 'red', attrs=['bold'])) return titre, firstname, surname, dateexp +def memberedit(titre, firstname, surname, clientID, dateinsc, dateexp): + while "the informations are incorrect": # Loop Filling informations + titre, firstname, surname, titrename = get_fullname(titre=titre, firstname=firstname, surname=surname) + + print("Titre : ", colored(titre, 'green')) + print("Prénom : ", colored(firstname, 'green')) + print("Nom : ", colored(surname, 'green')) + + correct = yes_or_no("Ces informations sont elles correctes ?") + os.system('cls') + + if correct: + wantnewpic = yes_or_no("Voulez-vous prendre une nouvelle photo ?") + os.system('cls') + if wantnewpic: + os.system('cls') + if version != 'devnocam': + picture = getpic() + else: + # We crop pic from the previous card + cartefilename = os.path.join(imgdir, clientID + '.pdf') + pdf = fitz.open(cartefilename) + page = pdf.loadPage(0) + mat = fitz.Matrix(4.165, 4.165) # To obtain good resolution + pix = page.getPixmap(matrix=mat) + + pageimg = Image.frombytes("RGBA", [pix.width, pix.height], pix.samples) + picture = pageimg.crop((47, 49, 343, 378)) + + barcode = barcode_gen(clientID) + fillcard(clientID, titrename, firstname, dateexp, barcode, picture) + cartefilename = mergepdf(clientID) + if version not in ('dev', 'devnocam'): + bkpdb() + printcard(cartefilename) + writeindb(titre, firstname, surname, clientID, dateinsc, dateexp, new=False) + os.system('cls') + break + return titre, firstname, surname, dateexp + + def main(): global IFPassDBdir, clientsfile, imgdir, clientsbkpfile, templatesdir, pngtemplate, fonttemplate, pdftemplate, printername, AcrobatReader while "The program is running": From ad2c7de56339f09605541b38c79b05313cdb915b Mon Sep 17 00:00:00 2001 From: Jordan ERNST Date: Tue, 5 Mar 2019 09:39:17 +0100 Subject: [PATCH 10/10] Edit desc --- IFPass.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IFPass.py b/IFPass.py index 73690a4..6cfacfc 100644 --- a/IFPass.py +++ b/IFPass.py @@ -531,7 +531,7 @@ def main(): print('Version : ', version) if version in ('dev', 'devnocam'): print(colored("\nATTENTION : Il s'agit d'une version en cours de développement, potentiellement instable !", 'red')) - print("\nLe programme IFPass à été écrit par Jordan ERNST Q1 2018 pour l'Institut Français en Hongrie.") + print("\nCe programme est developpé par par Jordan ERNST pour l'Institut Français en Hongrie.") print('Pour toute question, problème ou requête contactez-moi à pro.ernst@gmail.com.\n') print('1 - Nouveau membre', '2 - Rechercher un membre', '0 - Quitter', sep='\n') choix = input('Choix : ')