diff --git a/.gitignore b/.gitignore index c871d27..9c802d7 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,7 @@ __pycache__/ result* +.env + scratch.py test.py diff --git a/printer.py b/printer.py index bbae47c..8e377f1 100644 --- a/printer.py +++ b/printer.py @@ -1,6 +1,21 @@ -from escpos.printer import CupsPrinter +import logging +import os from itertools import zip_longest +from dotenv import find_dotenv, load_dotenv +from escpos.printer import CupsPrinter + +log = logging.getLogger("receipt-printer") +log.setLevel(logging.WARNING) + +if load_dotenv(find_dotenv(usecwd=True)): + log.debug("Loaded .env") +else: + log.debug("Didn't find .env") + + +RECEIPT_PRINTER = os.getenv("RECEIPT_PRINTER") + class CallbackContext: def __init__(self, enter=None, exit=None): @@ -72,7 +87,7 @@ class ReceiptPrinter(CupsPrinter): return CallbackContext(exit=super().set_with_default) def split(self, left, right, cols=48): - self.textln(f"{left:<{cols//2}}{right:<{cols//2}}") + self.textln(f"{left:<{cols // 2}}{right:<{cols // 2}}") def vsplit(self, *args, **kwargs): return Split2Context(self, *args, **kwargs) @@ -96,7 +111,15 @@ class ReceiptPrinter(CupsPrinter): def title(self, text, size=6, width=None, height=None): width = width or size height = height or size - with self.set(align="center", bold=True, invert=True, smooth=True, custom_size=True, width=width, height=height): + with self.set( + align="center", + bold=True, + invert=True, + smooth=True, + custom_size=True, + width=width, + height=height, + ): self.textln(text) self.ln() @@ -104,5 +127,5 @@ class ReceiptPrinter(CupsPrinter): with self.set(align="center", double_height=True, double_width=True): p.textln(text) -#p = ReceiptPrinter("EPSON-TM-m30", profile="default") -p = ReceiptPrinter("EPSON-TM-m30-remote", profile="default") + +p = ReceiptPrinter(RECEIPT_PRINTER, profile="default")