-
Notifications
You must be signed in to change notification settings - Fork 0
/
print.py
54 lines (43 loc) · 1.49 KB
/
print.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import glob
import json
import logging
import subprocess
import os
def print_image(img_file, config: dict):
"""Given a image file print the label"""
model = config['model']
printer = config['printer']
brother_ql_cmd = config['brother_ql_cmd']
abs_img_path = os.path.abspath(img_file)
# working command:
# brother_ql -m QL-500 -p usb://0x04f9:0x2015 print -l 29
# C:\Users\the_b\labdoo_print\brother_ql_labdoo_tags_printer\img\device_tag.png -r 90
bash_command = brother_ql_cmd + " -m " + model + " -p " + printer + " print -l 29 " + abs_img_path
# + " -r 90" no rotation right now
logging.info(bash_command)
subprocess.run(bash_command, shell=True)
print("")
input("Press Enter key to continue next image")
if __name__ == '__main__':
logging.basicConfig(
format="%(asctime)s: %(message)s",
# filemode='a',
# filename='HA-Watch.log',
level=logging.INFO,
datefmt="%H:%M:%S")
# Read Printer Configuration File
with open('config.json', 'r') as f:
conf = json.load(f)
for conf_elem in conf:
logging.info(str(conf_elem) + ": " + str(conf[conf_elem]))
logging.info("current OS: " + os.name)
try:
# PNGs in root folder
img_files = glob.glob("./*.png")
# Print the Labels
for img in img_files:
print_image(img, conf)
except Exception as exc:
logging.error("error:")
logging.error(exc)
logging.info("print job finished")