log vouchertype for printers
This commit is contained in:
		
							
								
								
									
										16
									
								
								main.py
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								main.py
									
									
									
									
									
								
							@@ -5,6 +5,7 @@ import requests
 | 
				
			|||||||
import csv
 | 
					import csv
 | 
				
			||||||
import qrcode
 | 
					import qrcode
 | 
				
			||||||
import io
 | 
					import io
 | 
				
			||||||
 | 
					import os
 | 
				
			||||||
from email.message import EmailMessage
 | 
					from email.message import EmailMessage
 | 
				
			||||||
from flask import Flask, request, jsonify, abort
 | 
					from flask import Flask, request, jsonify, abort
 | 
				
			||||||
from jinja2 import Template
 | 
					from jinja2 import Template
 | 
				
			||||||
@@ -63,15 +64,22 @@ def get_meal_times(meal_key):
 | 
				
			|||||||
        return "17:30 - 19:30"
 | 
					        return "17:30 - 19:30"
 | 
				
			||||||
    return ""
 | 
					    return ""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def log_printed(email, meal_key):
 | 
					def log_printed(email, meal_key, typ):
 | 
				
			||||||
    location = email.split("@")[0]
 | 
					    location = email.split("@")[0]
 | 
				
			||||||
    now = datetime.now()
 | 
					    now = datetime.now()
 | 
				
			||||||
    date_str = now.strftime("%Y-%m-%d")
 | 
					    date_str = now.strftime("%Y-%m-%d")
 | 
				
			||||||
    time_str = now.strftime("%H:%M:%S")
 | 
					    time_str = now.strftime("%H:%M:%S")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    file_exists = os.path.isfile("printed.csv")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    with open("printed.csv", "a", newline="") as csvfile:
 | 
					    with open("printed.csv", "a", newline="") as csvfile:
 | 
				
			||||||
        writer = csv.writer(csvfile, delimiter=";")
 | 
					        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):
 | 
					def generate_qr(secret):
 | 
				
			||||||
    qr = qrcode.QRCode(box_size=10, border=4)
 | 
					    qr = qrcode.QRCode(box_size=10, border=4)
 | 
				
			||||||
@@ -154,7 +162,7 @@ def order():
 | 
				
			|||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if email.endswith("@printme.local"):
 | 
					    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"}
 | 
					        return secret, 200, {"Content-Type": "text/plain; charset=utf-8"}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    qr_bytes = generate_qr(secret)
 | 
					    qr_bytes = generate_qr(secret)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user