Spaces:
Sleeping
Sleeping
File size: 1,264 Bytes
a38f710 e9349ad eb803dd a38f710 0d87629 e9349ad 0d87629 e9349ad 0d87629 e9349ad 0d87629 e9349ad | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | import qrcode
from pathlib import Path
import uuid
# Handle import for both package and direct execution
try:
from ..core.config import settings
except ImportError:
# If relative import fails, try absolute import
try:
from app.core.config import settings
except ImportError:
# Create a minimal settings object if import fails
class MinimalSettings:
QR_CODE_BOX_SIZE = 10
QR_CODE_BORDER = 4
settings = MinimalSettings()
def generate_qr_code_sync(data: str, output_path: Path, size: int) -> str:
"""
Generiert einen QR-Code und speichert ihn.
Gibt die UUID der generierten Datei (ohne Erweiterung) zurück.
Verwendet box_size und border aus den settings.
"""
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=settings.QR_CODE_BOX_SIZE,
border=settings.QR_CODE_BORDER,
)
qr.add_data(data)
qr.make(fit=True)
img = qr.make_image(fill_color="black", back_color="white")
output_path.mkdir(parents=True, exist_ok=True)
file_id = str(uuid.uuid4())
file_path_with_id = output_path / f"{file_id}.png"
img.save(file_path_with_id)
return file_id
|