log vouchertype for printers
This commit is contained in:
		
							
								
								
									
										16
									
								
								main.py
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								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)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user