Merge branch 'dev' into Member-Search

This commit is contained in:
Jordan ERNST 2018-04-24 15:48:01 +02:00
commit 5297fd2c5a
2 changed files with 58 additions and 56 deletions

4
.gitignore vendored
View File

@ -1 +1,5 @@
.ropeproject
Cartes
Clients_IFPass.csv
Clients_IFPass_backup.csv
IFPass.conf

110
IFPass.py
View File

@ -2,14 +2,11 @@
# 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
import csv
import code128
@ -25,46 +22,44 @@ from colorama import init
from termcolor import colored
version = '1.0'
version = 'devnocam' # dev/devnocam
computer = 'test' # 'test', 'mediatheque' or 'accueil'
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'
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'
config = 'IFPass.conf'
@contextmanager
def HideOutput(to=os.devnull):
fd = sys.stdout.fileno()
def initialisation():
conf = configparser.ConfigParser()
conf.optionxform = str # For case sensitive config file
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
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:
conf.read(config)
IFPassdir = conf['DEFAULT']['IFPassdir']
printername = conf['DEFAULT']['printername']
AcrobatReader = conf['DEFAULT']['AcrobatReader']
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
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')
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,7 +198,9 @@ def fillcard(barcode):
# Barcode + picture embedding :
im.paste(barcode,(556, 460))
im.paste(picture,(47, 49))
if version != 'devnocam':
im.paste(picture,(47, 49))
# Create PDF :
im = im.convert("RGB")
@ -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,9 +230,8 @@ 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 True:
@ -248,7 +243,9 @@ while True:
init()
f = Figlet(font='big')
print(colored(f.renderText('IFPass'), 'cyan', attrs=['bold']))
print('Version :', version)
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')
titre, firstname, surname, fullname = get_fullname()
@ -257,10 +254,10 @@ while True:
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
@ -277,15 +274,16 @@ while True:
if correct:
os.system('cls')
picture = getpic()
IFPassdir, printername, AcrobatReader, clientsfile, clientsbkpfile, imgdir, pdftemplate, pngtemplate, fonttemplate = initialisation()
if version != 'devnocam':
picture = getpic()
clientID = getclientID()
barcode = barcode_gen(clientID)
fillcard(barcode)
cartefilename = mergepdf()
bkpdb()
if computer == 'mediatheque' or computer == 'accueil':
if version not in ('dev', 'devnocam'):
bkpdb()
printcard(cartefilename)
elif choix == '2':
os.system('cls')
research = input('Entrez le nom, prénom, ou numéro de carte (ou flashez) : ').lower()