Merge branch 'dev' into Member-Search
This commit is contained in:
commit
5297fd2c5a
4
.gitignore
vendored
4
.gitignore
vendored
@ -1 +1,5 @@
|
|||||||
.ropeproject
|
.ropeproject
|
||||||
|
Cartes
|
||||||
|
Clients_IFPass.csv
|
||||||
|
Clients_IFPass_backup.csv
|
||||||
|
IFPass.conf
|
||||||
|
100
IFPass.py
100
IFPass.py
@ -2,14 +2,11 @@
|
|||||||
|
|
||||||
# Written by Jordan ERNST Q1 2018.
|
# Written by Jordan ERNST Q1 2018.
|
||||||
# Contact : pro.ernst@gmail.com
|
# 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 sys
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
from contextlib import contextmanager # To hide output
|
|
||||||
from datetime import date, timedelta
|
from datetime import date, timedelta
|
||||||
import csv
|
import csv
|
||||||
import code128
|
import code128
|
||||||
@ -25,46 +22,44 @@ from colorama import init
|
|||||||
from termcolor import colored
|
from termcolor import colored
|
||||||
|
|
||||||
|
|
||||||
version = '1.0'
|
version = 'devnocam' # dev/devnocam
|
||||||
|
|
||||||
computer = 'test' # 'test', 'mediatheque' or 'accueil'
|
config = 'IFPass.conf'
|
||||||
|
|
||||||
if computer == 'test':
|
|
||||||
IFPassdir = '\\\\192.168.1.1\SSIC\\04-Projets\IFPass\\'
|
def initialisation():
|
||||||
elif computer == 'mediatheque':
|
conf = configparser.ConfigParser()
|
||||||
IFPassdir = '\\\\192.168.1.1\IFPass\\'
|
conf.optionxform = str # For case sensitive config file
|
||||||
printername = ' XPS Pink Card Printer'
|
|
||||||
elif computer == 'accueil':
|
if not os.path.exists(config): # Check if config file exists
|
||||||
IFPassdir = '\\\\192.168.1.1\IFPass\\'
|
print('Fichier de configuration introuvable.')
|
||||||
printername = ' XPS Blue Card Printer'
|
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:
|
else:
|
||||||
print('La variable "computer" est mal définie.')
|
conf.read(config)
|
||||||
sys.exit()
|
IFPassdir = conf['DEFAULT']['IFPassdir']
|
||||||
|
printername = conf['DEFAULT']['printername']
|
||||||
clientsfile = IFPassdir + 'Clients_IFPass.csv'
|
AcrobatReader = conf['DEFAULT']['AcrobatReader']
|
||||||
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'
|
|
||||||
|
|
||||||
|
|
||||||
@contextmanager
|
clientsfile = os.path.join(IFPassdir, 'Clients_IFPass.csv')
|
||||||
def HideOutput(to=os.devnull):
|
clientsbkpfile = os.path.join(IFPassdir, 'Clients_IFPass_backup.csv')
|
||||||
fd = sys.stdout.fileno()
|
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):
|
if not os.path.exists(imgdir): # Cartes dir creation if it doesn't exist
|
||||||
sys.stdout.close() # + implicit flush()
|
os.makedirs(imgdir)
|
||||||
os.dup2(to.fileno(), fd) # fd writes to 'to' file
|
if not os.path.exists(clientsfile): # Creation Clients_File if it doesn't exist
|
||||||
sys.stdout = os.fdopen(fd, 'w') # Python writes to fd
|
with open(clientsfile, 'w', newline='', encoding='utf-8') as csvfile:
|
||||||
|
writer = csv.writer(csvfile, delimiter=';')
|
||||||
with os.fdopen(os.dup(fd), 'w') as old_stdout:
|
writer.writerow(['Titre', 'Prénom', 'Nom', 'Numéro de client', "Date d'inscription", "Date d'expiration"])
|
||||||
with open(to, 'w') as file:
|
return IFPassdir, printername, AcrobatReader, clientsfile, clientsbkpfile, imgdir, pdftemplate, pngtemplate, fonttemplate
|
||||||
_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
|
|
||||||
|
|
||||||
|
|
||||||
def get_fullname():
|
def get_fullname():
|
||||||
@ -127,19 +122,18 @@ def getpic():
|
|||||||
try:
|
try:
|
||||||
ret, frame = cap.read()
|
ret, frame = cap.read()
|
||||||
cv2.rectangle(frame, (170, 73), (470, 407), (0, 255, 0), 2)
|
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.',
|
cv2.imshow('IFCamera - Touche Espace pour prendre la photo, Echap pour une carte sans photo, Q pour quitter.', frame)
|
||||||
frame)
|
|
||||||
except cv2.error:
|
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")
|
os.system("pause")
|
||||||
sys.exit(0)
|
sys.exit()
|
||||||
SetForegroundWindow(find_window(title='IFCamera - Touche Espace '
|
SetForegroundWindow(find_window(title='IFCamera - Touche Espace '
|
||||||
'pour prendre la photo, Echap pour une carte sans photo, Q pour quitter.'))
|
'pour prendre la photo, Echap pour une carte sans photo, Q pour quitter.'))
|
||||||
k = cv2.waitKey(1)
|
k = cv2.waitKey(1)
|
||||||
if k == 27: # Echap
|
if k == 27: # Echap
|
||||||
print(colored('[OK]', 'green'))
|
print(colored('[OK]', 'green'))
|
||||||
cv2.destroyAllWindows()
|
cv2.destroyAllWindows()
|
||||||
defaultpicture = IFPassdir + 'Templates\default_avatar.jpg'
|
defaultpicture = os.path.join(IFPassdir, 'Templates', 'default_avatar.jpg')
|
||||||
picture = Image.open(defaultpicture)
|
picture = Image.open(defaultpicture)
|
||||||
return picture
|
return picture
|
||||||
elif k & 0xFF == ord(' '): # Space
|
elif k & 0xFF == ord(' '): # Space
|
||||||
@ -204,6 +198,8 @@ def fillcard(barcode):
|
|||||||
|
|
||||||
# Barcode + picture embedding :
|
# Barcode + picture embedding :
|
||||||
im.paste(barcode,(556, 460))
|
im.paste(barcode,(556, 460))
|
||||||
|
|
||||||
|
if version != 'devnocam':
|
||||||
im.paste(picture,(47, 49))
|
im.paste(picture,(47, 49))
|
||||||
|
|
||||||
# Create PDF :
|
# Create PDF :
|
||||||
@ -214,7 +210,7 @@ def fillcard(barcode):
|
|||||||
|
|
||||||
|
|
||||||
def mergepdf():
|
def mergepdf():
|
||||||
cartefilename = imgdir + clientID + '.pdf'
|
cartefilename = os.path.join(imgdir, clientID + '.pdf')
|
||||||
output = PdfFileWriter()
|
output = PdfFileWriter()
|
||||||
|
|
||||||
pdf1 = PdfFileReader(imgdir + clientID + '_Front.pdf', 'rb')
|
pdf1 = PdfFileReader(imgdir + clientID + '_Front.pdf', 'rb')
|
||||||
@ -234,9 +230,8 @@ def mergepdf():
|
|||||||
|
|
||||||
|
|
||||||
def printcard(cartefilename):
|
def printcard(cartefilename):
|
||||||
# CMD : "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" /h /n /t Carte.pdf "XPS Pink Card Printer"
|
# Working : subprocess.Popen('"C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" /h /n /t ' + cartefilename + ' '+ printername, shell=False)
|
||||||
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)
|
||||||
print('test')
|
|
||||||
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
@ -249,6 +244,8 @@ while True:
|
|||||||
f = Figlet(font='big')
|
f = Figlet(font='big')
|
||||||
print(colored(f.renderText('IFPass'), 'cyan', attrs=['bold']))
|
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('\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('Pour toute question ou problème contactez-moi à pro.ernst@gmail.com.\n')
|
||||||
titre, firstname, surname, fullname = get_fullname()
|
titre, firstname, surname, fullname = get_fullname()
|
||||||
@ -257,10 +254,10 @@ while True:
|
|||||||
|
|
||||||
dateinsc = dateinsc.strftime('%d/%m/%Y')
|
dateinsc = dateinsc.strftime('%d/%m/%Y')
|
||||||
dateexp = dateexp.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:
|
if changeexp:
|
||||||
while True:
|
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)
|
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:
|
if match:
|
||||||
break
|
break
|
||||||
@ -277,15 +274,16 @@ while True:
|
|||||||
|
|
||||||
if correct:
|
if correct:
|
||||||
os.system('cls')
|
os.system('cls')
|
||||||
|
IFPassdir, printername, AcrobatReader, clientsfile, clientsbkpfile, imgdir, pdftemplate, pngtemplate, fonttemplate = initialisation()
|
||||||
|
if version != 'devnocam':
|
||||||
picture = getpic()
|
picture = getpic()
|
||||||
clientID = getclientID()
|
clientID = getclientID()
|
||||||
barcode = barcode_gen(clientID)
|
barcode = barcode_gen(clientID)
|
||||||
fillcard(barcode)
|
fillcard(barcode)
|
||||||
cartefilename = mergepdf()
|
cartefilename = mergepdf()
|
||||||
|
if version not in ('dev', 'devnocam'):
|
||||||
bkpdb()
|
bkpdb()
|
||||||
if computer == 'mediatheque' or computer == 'accueil':
|
|
||||||
printcard(cartefilename)
|
printcard(cartefilename)
|
||||||
|
|
||||||
elif choix == '2':
|
elif choix == '2':
|
||||||
os.system('cls')
|
os.system('cls')
|
||||||
research = input('Entrez le nom, prénom, ou numéro de carte (ou flashez) : ').lower()
|
research = input('Entrez le nom, prénom, ou numéro de carte (ou flashez) : ').lower()
|
||||||
|
Loading…
Reference in New Issue
Block a user