Compare commits
21 Commits
Author | SHA1 | Date | |
---|---|---|---|
c7026ce9d3 | |||
f1bc7d4fae | |||
d956ab621e | |||
0354a586a6 | |||
7dc3d229e9 | |||
f9b62fc805 | |||
5297fd2c5a | |||
63c12029c4 | |||
040e3e9033 | |||
09fd78f425 | |||
13cfdf630c | |||
bc7482b29f | |||
7b23fe7b94 | |||
29e35f5a0f | |||
9b562c2a70 | |||
18ae29bc21 | |||
cce390b365 | |||
aae57761ba | |||
6a6971b680 | |||
9dae03073a | |||
46e18814a4 |
4
.gitignore
vendored
4
.gitignore
vendored
@ -1 +1,5 @@
|
||||
.ropeproject
|
||||
Cartes
|
||||
Clients_IFPass.csv
|
||||
Clients_IFPass_backup.csv
|
||||
IFPass.conf
|
||||
|
@ -1,3 +0,0 @@
|
||||
## 1.0 (23/03/2018)
|
||||
|
||||
### First IFPass release
|
@ -1 +0,0 @@
|
||||
Titre;Prénom;Nom;Numéro de client;Date d'inscripton;Date d'expiration
|
|
@ -1 +1,61 @@
|
||||
Titre;Prénom;Nom;Numéro de client;Date d'inscripton;Date d'expiration
|
||||
Titre;Prénom;Nom;Numéro de client;Date d'inscripton;Date d'expiration
|
||||
;Jordan;ERNST;0000000001;21/03/2018;01/09/2019
|
||||
;Otto;MAJOROS;0000000002;21/03/2018;21/03/2019
|
||||
;Beata;LICSKO-TAKACS;0000000003;21/03/2018;21/03/2019
|
||||
;Timea;KLINCSEK;0000000004;22/03/2018;22/03/2019
|
||||
;Lili;PAMUK;0000000005;22/03/2018;22/03/2019
|
||||
;Petra;ZAJKÁS;0000000006;22/03/2018;22/03/2019
|
||||
;Corinne;GARDINI;0000000007;23/03/2018;23/03/2019
|
||||
;Nora;DIRAMERIAN;0000000008;23/03/2018;23/03/2050
|
||||
;Hedvig;ANTAL;0000000009;23/03/2018;23/03/2019
|
||||
;Hedvig;ANTAL;0000000010;23/03/2018;23/03/2019
|
||||
;Annabelle;LAGOA;0000000011;23/03/2018;23/03/2019
|
||||
;Erika;BALÁZS;0000000012;23/03/2018;23/03/2019
|
||||
;Krisztina;KIS;0000000013;23/03/2018;23/03/2019
|
||||
;Zsuzsanna;STIFFEL;0000000014;23/03/2018;23/03/2019
|
||||
;Martin;SANCHEZ;0000000015;23/03/2018;23/03/2019
|
||||
;Melinda;ERDŐHÁTI;0000000016;23/03/2018;23/03/2019
|
||||
;Zoltán;UZSÁK;0000000017;23/03/2018;23/03/2019
|
||||
;Péter;RÓZSA;0000000018;23/03/2018;23/03/2019
|
||||
;Ildikó;PUSZTAI;0000000019;23/03/2018;23/03/2019
|
||||
;Robert;KABA LOEMBA;0000000020;23/03/2018;23/03/2019
|
||||
;Ildikó;HORVÁTH;0000000021;24/03/2018;24/03/2019
|
||||
;Nora;MOHAMED-ELSAYED;0000000022;24/03/2018;24/03/2019
|
||||
;Dóra;MUNKÁS;0000000023;24/03/2018;24/03/2019
|
||||
;Nathalie;VAN PEE;0000000024;24/03/2018;24/03/2019
|
||||
;Gabriella;SZALAY;0000000025;24/03/2018;24/03/2019
|
||||
;Ambrus;GERGELY;0000000026;24/03/2018;24/03/2019
|
||||
;Mónika;GODA;0000000027;24/03/2018;24/03/2019
|
||||
;Laura;HOLLÓSI;0000000028;24/03/2018;24/03/2019
|
||||
;Magdolna;LEVAI;0000000029;24/03/2018;24/03/2019
|
||||
;Péter;LÔTE;0000000030;24/03/2018;24/03/2019
|
||||
;Judit;WEISZ;0000000031;24/03/2018;24/03/2019
|
||||
;Gergely;BABA;0000000032;24/03/2018;24/03/2019
|
||||
;Annamária;SINKOVICS;0000000033;24/03/2018;24/03/2019
|
||||
;Eszter;MALYATA;0000000034;27/03/2018;27/03/2019
|
||||
;Andrea;GORZO;0000000035;27/03/2018;27/03/2019
|
||||
;Béláné;POMOGÁTS;0000000036;27/03/2018;27/03/2019
|
||||
;Zsofia;HORVATH;0000000037;27/03/2018;27/03/2019
|
||||
;Adrienn;GULYÁS;0000000038;27/03/2018;27/03/2019
|
||||
;Rózsa;PERLAKI;0000000039;27/03/2018;27/03/2019
|
||||
;Gábor Dániel;ZAMARÓCZY;0000000040;27/03/2018;27/03/2019
|
||||
;Grégory;LUCAS;0000000041;28/03/2018;28/03/2019
|
||||
;Lajos;HORVÁTH;0000000042;28/03/2018;28/03/2019
|
||||
;Rachel;HIDAS;0000000043;28/03/2018;28/03/2019
|
||||
;Dominika;DUDÁS;0000000044;28/03/2018;28/03/2019
|
||||
;Tímea;MAZZAG;0000000045;28/03/2018;28/03/2019
|
||||
;Klára;NÉGYESI;0000000046;29/03/2018;29/03/2019
|
||||
;Xy;XY;0000000047;29/03/2018;29/03/2019
|
||||
Dr.;Aniko;RADVANSZKY;0000000048;29/03/2018;29/03/2019
|
||||
Dr.;Krisztina;KALMAN;0000000049;29/03/2018;29/03/2019
|
||||
;Janos;SZOKE;0000000050;29/03/2018;29/03/2019
|
||||
;Kata Lidia;HIDASI;0000000051;29/03/2018;29/03/2019
|
||||
;Dóra;HORVÁTH;0000000052;29/03/2018;29/03/2019
|
||||
;Olivier;CHIQUET;0000000053;29/03/2018;29/03/2019
|
||||
;Anne;LARNICOL;0000000054;29/03/2018;29/03/2019
|
||||
;Tamas;MEITNER;0000000055;03/04/2018;03/04/2019
|
||||
;Gyorgy;ONOZO;0000000056;03/04/2018;03/04/2019
|
||||
;Dorothee;MEENS;0000000057;03/04/2018;03/04/2019
|
||||
;Gergo;JANKOVICS;0000000058;03/04/2018;03/04/2019
|
||||
;Lenka;JAROLIMOVA;0000000059;03/04/2018;03/04/2019
|
||||
;Franck;LEFEBVRE;0000000060;03/04/2018;03/04/2019
|
||||
|
|
177
IFPass.py
177
IFPass.py
@ -2,15 +2,12 @@
|
||||
|
||||
# Written by Jordan ERNST Q1 2018.
|
||||
# Contact : pro.ernst@gmail.com
|
||||
# v1.0 : 23/03/2018
|
||||
|
||||
# https://www.pyimagesearch.com/2015/12/21/increasing-webcam-fps-with-python-and-opencv/
|
||||
|
||||
import configparser
|
||||
import sys
|
||||
import os
|
||||
import re
|
||||
from contextlib import contextmanager # To hide output
|
||||
from datetime import date, timedelta
|
||||
from datetime import date, timedelta, datetime
|
||||
import csv
|
||||
import code128
|
||||
import cv2
|
||||
@ -25,46 +22,44 @@ from colorama import init
|
||||
from termcolor import colored
|
||||
|
||||
|
||||
version = '1.0'
|
||||
version = '2.0'
|
||||
|
||||
computer = '' # 'test', 'mediatheque' or 'accueil'
|
||||
config = 'IFPass.conf'
|
||||
|
||||
if computer == 'test':
|
||||
IFPassdir = '\\\\192.168.1.1\SSIC\\04-Projets\IFPass\\'
|
||||
elif computer == 'mediatheque':
|
||||
IFPassdir = '\\\\192.168.1.1\IFPass\\'
|
||||
printername = ' XPS Pink Card Printer'
|
||||
elif computer == 'accueil':
|
||||
IFPassdir = '\\\\192.168.1.1\IFPass\\'
|
||||
printername = ' XPS Blue Card Printer'
|
||||
|
||||
def initialisation():
|
||||
conf = configparser.ConfigParser()
|
||||
conf.optionxform = str # For case sensitive config file
|
||||
|
||||
if not os.path.exists(config): # Check if config file exists
|
||||
print('Fichier de configuration introuvable.')
|
||||
IFPassdir = input(r'Quel est le répertoire IFPass ? (Ex : \\192.168.1.1\IFPass) : ')
|
||||
printername = input("Quel est le nom de l'imprimante à cartes ? : " )
|
||||
AcrobatReader = input(r"Quel est le chemain vers Acrobat Reader ? ( Ex : C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe) : ")
|
||||
conf['DEFAULT'] = {'IFPassdir': IFPassdir, 'printername': printername, 'AcrobatReader': AcrobatReader}
|
||||
with open(config, 'w') as configfile:
|
||||
conf.write(configfile)
|
||||
else:
|
||||
print('La variable "computer" est mal définie.')
|
||||
sys.exit()
|
||||
|
||||
clientsfile = IFPassdir + 'Clients_IFPass.csv'
|
||||
clientsbkpfile = IFPassdir + 'Clients_IFPass_bakup.csv'
|
||||
imgdir = IFPassdir + 'Cartes\\'
|
||||
pdftemplate = IFPassdir + 'Templates\IFPass_PDF_Template.pdf'
|
||||
pngtemplate = IFPassdir + 'Templates\IFPass_PNG_Template.png'
|
||||
fonttemplate = IFPassdir + 'Templates\Roboto-Bold.ttf'
|
||||
conf.read(config)
|
||||
IFPassdir = conf['DEFAULT']['IFPassdir']
|
||||
printername = conf['DEFAULT']['printername']
|
||||
AcrobatReader = conf['DEFAULT']['AcrobatReader']
|
||||
|
||||
|
||||
@contextmanager
|
||||
def HideOutput(to=os.devnull):
|
||||
fd = sys.stdout.fileno()
|
||||
clientsfile = os.path.join(IFPassdir, 'Clients_IFPass.csv')
|
||||
clientsbkpfile = os.path.join(IFPassdir, 'Clients_IFPass_backup.csv')
|
||||
imgdir = os.path.join(IFPassdir, 'Cartes')
|
||||
pdftemplate = os.path.join(IFPassdir, 'Templates', 'IFPass_PDF_Template.pdf')
|
||||
pngtemplate = os.path.join(IFPassdir, 'Templates', 'IFPass_PNG_Template.png')
|
||||
fonttemplate = os.path.join(IFPassdir, 'Templates', 'Roboto-Bold.ttf')
|
||||
|
||||
def _redirect_stdout(to):
|
||||
sys.stdout.close() # + implicit flush()
|
||||
os.dup2(to.fileno(), fd) # fd writes to 'to' file
|
||||
sys.stdout = os.fdopen(fd, 'w') # Python writes to fd
|
||||
|
||||
with os.fdopen(os.dup(fd), 'w') as old_stdout:
|
||||
with open(to, 'w') as file:
|
||||
_redirect_stdout(to=file)
|
||||
try:
|
||||
yield # allow code to be run with the redirected stdout
|
||||
finally:
|
||||
_redirect_stdout(to=old_stdout) # restore stdout. # cv2.selectROI
|
||||
if not os.path.exists(imgdir): # Cartes dir creation if it doesn't exist
|
||||
os.makedirs(imgdir)
|
||||
if not os.path.exists(clientsfile): # Creation Clients_File if it doesn't exist
|
||||
with open(clientsfile, 'w', newline='', encoding='utf-8') as csvfile:
|
||||
writer = csv.writer(csvfile, delimiter=';')
|
||||
writer.writerow(['Titre', 'Prénom', 'Nom', 'Numéro de client', "Date d'inscription", "Date d'expiration"])
|
||||
return IFPassdir, printername, AcrobatReader, clientsfile, clientsbkpfile, imgdir, pdftemplate, pngtemplate, fonttemplate
|
||||
|
||||
|
||||
def get_fullname():
|
||||
@ -127,19 +122,18 @@ def getpic():
|
||||
try:
|
||||
ret, frame = cap.read()
|
||||
cv2.rectangle(frame, (170, 73), (470, 407), (0, 255, 0), 2)
|
||||
cv2.imshow('IFCamera - Touche Espace pour prendre la photo, Echap pour une carte sans photo, Q pour quitter.',
|
||||
frame)
|
||||
cv2.imshow('IFCamera - Touche Espace pour prendre la photo, Echap pour une carte sans photo, Q pour quitter.', frame)
|
||||
except cv2.error:
|
||||
print('\nLa webcam est débranchée. Branchez-la, puis relancez le programme.')
|
||||
print(colored('\nLa webcam est débranchée. Branchez-la, puis relancez le programme.', 'red'))
|
||||
os.system("pause")
|
||||
sys.exit(0)
|
||||
sys.exit()
|
||||
SetForegroundWindow(find_window(title='IFCamera - Touche Espace '
|
||||
'pour prendre la photo, Echap pour une carte sans photo, Q pour quitter.'))
|
||||
k = cv2.waitKey(1)
|
||||
if k == 27: # Echap
|
||||
print(colored('[OK]', 'green'))
|
||||
cv2.destroyAllWindows()
|
||||
defaultpicture = IFPassdir + 'Templates\default_avatar.jpg'
|
||||
defaultpicture = os.path.join(IFPassdir, 'Templates', 'default_avatar.jpg')
|
||||
picture = Image.open(defaultpicture)
|
||||
return picture
|
||||
elif k & 0xFF == ord(' '): # Space
|
||||
@ -204,6 +198,8 @@ def fillcard(barcode):
|
||||
|
||||
# Barcode + picture embedding :
|
||||
im.paste(barcode,(556, 460))
|
||||
|
||||
if version != 'devnocam':
|
||||
im.paste(picture,(47, 49))
|
||||
|
||||
# Create PDF :
|
||||
@ -214,7 +210,7 @@ def fillcard(barcode):
|
||||
|
||||
|
||||
def mergepdf():
|
||||
cartefilename = imgdir + clientID + '.pdf'
|
||||
cartefilename = os.path.join(imgdir, clientID + '.pdf')
|
||||
output = PdfFileWriter()
|
||||
|
||||
pdf1 = PdfFileReader(imgdir + clientID + '_Front.pdf', 'rb')
|
||||
@ -234,29 +230,92 @@ def mergepdf():
|
||||
|
||||
|
||||
def printcard(cartefilename):
|
||||
# CMD : "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" /h /n /t Carte.pdf "XPS Pink Card Printer"
|
||||
subprocess.Popen('"C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" /h /n /t ' + cartefilename + printername, shell=False)
|
||||
print('test')
|
||||
# Working : subprocess.Popen('"C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" /h /n /t ' + cartefilename + ' '+ printername, shell=False)
|
||||
subprocess.Popen('"' + AcrobatReader + '"' + ' /h /n /t ' + cartefilename + ' '+ printername, shell=False)
|
||||
|
||||
|
||||
while "the informations are incorrect": # Loop Filling informations
|
||||
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')
|
||||
init()
|
||||
f = Figlet(font='big')
|
||||
print(colored(f.renderText('IFPass'), 'cyan', attrs=['bold']))
|
||||
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.')
|
||||
print('Pour toute question ou problème contactez-moi à pro.ernst@gmail.com.\n')
|
||||
print('1 - Nouveau membre', '2 - Rechercher un membre', '3 - Quitter', sep='\n')
|
||||
choix = input('Choix : ')
|
||||
if choix == '1':
|
||||
while "the informations are incorrect": # Loop Filling informations
|
||||
os.system('cls')
|
||||
|
||||
titre, firstname, surname, fullname = 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 ?')
|
||||
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)? : ')
|
||||
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
|
||||
@ -273,11 +332,23 @@ while "the informations are incorrect": # Loop Filling informations
|
||||
|
||||
if correct:
|
||||
os.system('cls')
|
||||
if version != 'devnocam':
|
||||
picture = getpic()
|
||||
clientID = getclientID()
|
||||
barcode = barcode_gen(clientID)
|
||||
fillcard(barcode)
|
||||
cartefilename = mergepdf()
|
||||
if version not in ('dev', 'devnocam'):
|
||||
bkpdb()
|
||||
if computer == 'mediatheque' or computer == 'accueil':
|
||||
printcard(cartefilename)
|
||||
elif choix == '2':
|
||||
os.system('cls')
|
||||
membersearch()
|
||||
|
||||
elif choix == '3':
|
||||
sys.exit()
|
||||
|
||||
else:
|
||||
os.system('cls')
|
||||
print(colored('Choix incorrect !', 'red', attrs=['bold']))
|
||||
os.system("pause")
|
||||
|
Binary file not shown.
Reference in New Issue
Block a user