From 25dd6be2fc8ed46c75b0cd3d822b6819a562e4ae Mon Sep 17 00:00:00 2001 From: Thomas Date: Thu, 4 Apr 2024 22:44:12 +0200 Subject: [PATCH] Add qr code in payload --- core/app/handlers/core.py | 29 ++++++++++++++++++++++++++++- core/requirements.txt | 3 ++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/core/app/handlers/core.py b/core/app/handlers/core.py index d3763a6..eb3573d 100644 --- a/core/app/handlers/core.py +++ b/core/app/handlers/core.py @@ -1,5 +1,7 @@ import hug, os, random, string from kubernetes import client, config +import qrcode +from PIL import Image @hug.post('/create-room') def create_room(): @@ -49,7 +51,32 @@ def create_room(): networking.patch_namespaced_ingress(ingress, namespace, current_ingress) - return pod_id + # QR code + url = value=os.environ["BACKEND_URL"] + "/" + pod_id + qr = qrcode.QRCode( + version=1, + error_correction=qrcode.constants.ERROR_CORRECT_L, + box_size=10, + border=4, + ) + qr.add_data(url) + qr.make(fit=True) + + # Créer une image PIL à partir du QR code + img = qr.make_image(fill_color="black", back_color="white") + + # Convertir l'image PIL en tableau de 0 et de 1 + qr_array = [] + width, height = img.size + pixels = img.load() + for y in range(height): + row = [] + for x in range(width): + # Si le pixel est noir (représentant le code QR), ajouter 1, sinon 0 + row.append(1 if pixels[x, y] == 0 else 0) + qr_array.append(row) + + return {"instance": pod_id, "qr_code": qr_array} @hug.post('/delete-room') def delete_room(body): diff --git a/core/requirements.txt b/core/requirements.txt index 2d348f1..9ab860d 100644 --- a/core/requirements.txt +++ b/core/requirements.txt @@ -1,3 +1,4 @@ hug == 2.4.8 kubernetes == 29.0.0 -hug-middleware-cors == 1.0.0 \ No newline at end of file +hug-middleware-cors == 1.0.0 +qrcode == 7.4.2 \ No newline at end of file