43 lines
782 B
Python
43 lines
782 B
Python
import json
|
|
|
|
from escpos import printer
|
|
|
|
|
|
class Item:
|
|
def __init__(self, text, icon):
|
|
self.text = text
|
|
self.icon = icon
|
|
|
|
def print(self, conn):
|
|
conn.text(f"{self.text}\n")
|
|
# TODO: conn.image(self.icon)
|
|
conn.cut()
|
|
|
|
|
|
def connect(connection_cfg):
|
|
if "file" in connection_cfg:
|
|
return printer.File(connection_cfg["file"])
|
|
else:
|
|
return printer.Dummy()
|
|
|
|
|
|
def load_items(items_cfg):
|
|
return [Item(c['text'], c['img']) for c in items_cfg]
|
|
|
|
|
|
def main():
|
|
with open("config.json") as fh:
|
|
cfg = json.load(fh)
|
|
|
|
items = load_items(cfg['items'])
|
|
conn = connect(cfg["connection"])
|
|
|
|
for i in items:
|
|
i.print(conn)
|
|
|
|
print(conn.output.decode('UTF-8'))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|