Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
537d3725d7 | |||
8c552af606 | |||
6b900ef16d | |||
d028ecb842 | |||
c51c95c42b | |||
00d737714b | |||
d06716ac92 | |||
a60cfae01c | |||
fe07e61505 | |||
357e47cc73 | |||
c242c75b6b | |||
96ee09c7be | |||
935344d581 | |||
2561febca9 | |||
c53baccb38 |
30
app.py
30
app.py
@ -4,7 +4,7 @@ import threading
|
|||||||
import queue
|
import queue
|
||||||
import pdf2image
|
import pdf2image
|
||||||
from brother_ql.conversion import convert
|
from brother_ql.conversion import convert
|
||||||
from brother_ql.backends.helpers import send
|
from brother_ql.backends.helpers import send, status
|
||||||
from brother_ql.raster import BrotherQLRaster
|
from brother_ql.raster import BrotherQLRaster
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
import mimetypes
|
import mimetypes
|
||||||
@ -16,12 +16,19 @@ app = Flask(__name__)
|
|||||||
|
|
||||||
# Set up logging
|
# Set up logging
|
||||||
log_file = 'log.txt'
|
log_file = 'log.txt'
|
||||||
|
|
||||||
|
# Create a rotating file handler for logging
|
||||||
log_handler = RotatingFileHandler(log_file, maxBytes=10*1024*1024, backupCount=5) # 10MB per log file, keep 5 backups
|
log_handler = RotatingFileHandler(log_file, maxBytes=10*1024*1024, backupCount=5) # 10MB per log file, keep 5 backups
|
||||||
log_handler.setLevel(logging.INFO)
|
log_handler.setLevel(logging.DEBUG)
|
||||||
log_formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
|
log_formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
|
||||||
log_handler.setFormatter(log_formatter)
|
log_handler.setFormatter(log_formatter)
|
||||||
|
|
||||||
|
# Add the log handler to the Flask app's logger
|
||||||
app.logger.addHandler(log_handler)
|
app.logger.addHandler(log_handler)
|
||||||
|
|
||||||
|
# Ensure Flask app uses our logger, not its default one
|
||||||
|
app.logger.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
# Create a queue to hold the files for processing
|
# Create a queue to hold the files for processing
|
||||||
file_queue = queue.Queue()
|
file_queue = queue.Queue()
|
||||||
|
|
||||||
@ -55,10 +62,17 @@ def print_address_label(pdf_path):
|
|||||||
if not image:
|
if not image:
|
||||||
raise Exception("Failed to create label images")
|
raise Exception("Failed to create label images")
|
||||||
|
|
||||||
target_width = 1164
|
if 'address' in pdf_path.lower():
|
||||||
target_height = 1660
|
target_width = 1660
|
||||||
image = image.convert("RGB")
|
target_height = 1164
|
||||||
image = image.resize((target_width, target_height), Image.LANCZOS)
|
image = image.convert("RGB")
|
||||||
|
image = image.resize((target_width, target_height), Image.LANCZOS)
|
||||||
|
image = image.rotate(90, expand=True)
|
||||||
|
else:
|
||||||
|
target_width = 1164
|
||||||
|
target_height = 1660
|
||||||
|
image = image.convert("RGB")
|
||||||
|
image = image.resize((target_width, target_height), Image.LANCZOS)
|
||||||
|
|
||||||
qlr = BrotherQLRaster(printer_model)
|
qlr = BrotherQLRaster(printer_model)
|
||||||
qlr.exception_on_warning = True
|
qlr.exception_on_warning = True
|
||||||
@ -78,12 +92,13 @@ def print_address_label(pdf_path):
|
|||||||
)
|
)
|
||||||
|
|
||||||
app.logger.info("Sending to printer...")
|
app.logger.info("Sending to printer...")
|
||||||
send(
|
status = send(
|
||||||
instructions=instructions,
|
instructions=instructions,
|
||||||
printer_identifier=printer,
|
printer_identifier=printer,
|
||||||
backend_identifier=backend,
|
backend_identifier=backend,
|
||||||
blocking=True
|
blocking=True
|
||||||
)
|
)
|
||||||
|
app.logger.info(f"Printer status: {status}")
|
||||||
app.logger.info("Print job sent successfully")
|
app.logger.info("Print job sent successfully")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -99,7 +114,6 @@ def process_queue():
|
|||||||
# Process the file (convert and print)
|
# Process the file (convert and print)
|
||||||
app.logger.info(f"Processing file: {file_path}")
|
app.logger.info(f"Processing file: {file_path}")
|
||||||
print_address_label(file_path)
|
print_address_label(file_path)
|
||||||
time.sleep(10)
|
|
||||||
# Signal that the task is done
|
# Signal that the task is done
|
||||||
file_queue.task_done()
|
file_queue.task_done()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user