From a862de190f193fa27a9e36f8f70839c1edc97d60 Mon Sep 17 00:00:00 2001 From: Thies Mueller <> Date: Wed, 24 Sep 2025 20:27:57 +0200 Subject: [PATCH] log vouchertype for printers --- main.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 4bdeb78..2c07538 100644 --- a/main.py +++ b/main.py @@ -5,6 +5,7 @@ import requests import csv import qrcode import io +import os from email.message import EmailMessage from flask import Flask, request, jsonify, abort from jinja2 import Template @@ -63,15 +64,22 @@ def get_meal_times(meal_key): return "17:30 - 19:30" return "" -def log_printed(email, meal_key): +def log_printed(email, meal_key, typ): location = email.split("@")[0] now = datetime.now() date_str = now.strftime("%Y-%m-%d") time_str = now.strftime("%H:%M:%S") + + file_exists = os.path.isfile("printed.csv") + with open("printed.csv", "a", newline="") as csvfile: writer = csv.writer(csvfile, delimiter=";") - writer.writerow([date_str, time_str, meal_key, location]) - debug_print(f"[DEBUG] Logged printed PDF: {location} - {meal_key}") + + if not file_exists: + writer.writerow(["Datum", "Zeit", "Mahlzeit", "Vouchertyp", "Location"]) + writer.writerow([date_str, time_str, meal_key, typ, location]) + + debug_print(f"[DEBUG] Logged printed PDF: {location} - {meal_key} - {typ}") def generate_qr(secret): qr = qrcode.QRCode(box_size=10, border=4) @@ -154,7 +162,7 @@ def order(): ) if email.endswith("@printme.local"): - log_printed(email, meal_key) + log_printed(email, meal_key, typ) return secret, 200, {"Content-Type": "text/plain; charset=utf-8"} qr_bytes = generate_qr(secret)