Commit 7a3841c3 authored by pa's avatar pa 🌊

pouet

parent 6f83b8fa
Pipeline #4579 canceled with stages
in 1 minute and 48 seconds
......@@ -17,7 +17,8 @@ except ImportError:
def main():
parser = argparse.ArgumentParser(description='Generate attestation de sortie')
parser = argparse.ArgumentParser(
description='Generate attestation de sortie')
parser.add_argument('-p', '--profile', type=str)
parser.add_argument('-r', '--reasons', type=int)
parser.add_argument('-a', '--auto', action='store_true')
......@@ -36,21 +37,20 @@ def main():
print('Profile doesn\'t exists')
sys.exit(1)
parameters = {
'lastname' : 'Nom',
'firstname' : 'Prenom',
'birthday' : 'Date de naissance',
'placeofbirth' : 'Lieu de naissance',
'address' : 'Adresse',
'city' : 'Ville',
'zipcode' : 'Code postal'
}
'lastname': 'Nom',
'firstname': 'Prenom',
'birthday': 'Date de naissance',
'placeofbirth': 'Lieu de naissance',
'address': 'Adresse',
'city': 'Ville',
'zipcode': 'Code postal'
}
# Prompt user some info
for k,v in parameters.items():
for k, v in parameters.items():
if k not in config.keys():
config[k] = input(v+' : ')
config[k] = input(v + ' : ')
if args.auto:
datesortie = datetime.date.today().strftime("%d/%m/%y")
......@@ -87,29 +87,38 @@ def main():
# Generate QRCode
qrcode_file = tempfile.NamedTemporaryFile(suffix=".png")
q = qrcode.make(f"Cree le: {creationdate} a {creationhour};"
f"Nom: {config['lastname']};"
f"Prenom: {config['firstname']};"
f"Naissance: {config['birthday']} a {config['placeofbirth']};"
f"Adresse: {config['address']} {config['zipcode']} {config['city']};"
f"Sortie: {datesortie} a {heuresortie};"
f"Motifs: {reasons_list[reasons]};")
q = qrcode.make(
f"Cree le: {creationdate} a {creationhour};"
f"Nom: {config['lastname']};"
f"Prenom: {config['firstname']};"
f"Naissance: {config['birthday']} a {config['placeofbirth']};"
f"Adresse: {config['address']} {config['zipcode']} {config['city']};"
f"Sortie: {datesortie} a {heuresortie};"
f"Motifs: {reasons_list[reasons]};")
q.save(qrcode_file.name)
# Generate text page
# This is a watermark which will be applied to the blank attestation
text_page_buf = io.BytesIO()
text_page_canvas = reportlab.pdfgen.canvas.Canvas(text_page_buf, pagesize=reportlab.lib.pagesizes.A4)
text_page_canvas = reportlab.pdfgen.canvas.Canvas(
text_page_buf, pagesize=reportlab.lib.pagesizes.A4)
text_page_canvas.setFont('Helvetica', 11)
text_page_canvas.drawString(119, 696, f"{config['firstname']} {config['lastname']}")
text_page_canvas.drawString(119, 696,
f"{config['firstname']} {config['lastname']}")
text_page_canvas.drawString(119, 674, config['birthday'])
text_page_canvas.drawString(297, 674, config['placeofbirth'])
text_page_canvas.drawString(133, 652, f"{config['address']} {config['zipcode']} {config['city']}")
text_page_canvas.drawString(
133, 652, f"{config['address']} {config['zipcode']} {config['city']}")
text_page_canvas.drawString(105, 177, config['city'])
text_page_canvas.drawString(91, 153, creationdate)
text_page_canvas.drawString(264, 153, datetime.datetime.now().strftime("%H:%M"))
text_page_canvas.drawString(264, 153,
datetime.datetime.now().strftime("%H:%M"))
a4_width, a4_height = reportlab.lib.pagesizes.A4
text_page_canvas.drawImage(qrcode_file.name, a4_width - 156, 100, width=92, height=92)
text_page_canvas.drawImage(qrcode_file.name,
a4_width - 156,
100,
width=92,
height=92)
text_page_canvas.setFont('Helvetica', 18)
ys = [578, 533, 477, 435, 396, 358, 295, 255, 211]
text_page_canvas.drawString(84, ys[reasons], 'x')
......@@ -119,8 +128,13 @@ def main():
# Generate QRCode page
qrcode_page_buf = io.BytesIO()
qrcode_page_canvas = reportlab.pdfgen.canvas.Canvas(qrcode_page_buf, pagesize=reportlab.lib.pagesizes.A4)
qrcode_page_canvas.drawImage(qrcode_file.name, 50, a4_height - 350, width=300, height=300)
qrcode_page_canvas = reportlab.pdfgen.canvas.Canvas(
qrcode_page_buf, pagesize=reportlab.lib.pagesizes.A4)
qrcode_page_canvas.drawImage(qrcode_file.name,
50,
a4_height - 350,
width=300,
height=300)
qrcode_page_canvas.save()
qrcode_page_buf.seek(0)
qrcode_page = PdfFileReader(qrcode_page_buf).getPage(0)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment