-
Notifications
You must be signed in to change notification settings - Fork 0
/
invetory.py
73 lines (61 loc) · 2.08 KB
/
invetory.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import qrcode
import brother_ql
from PIL import Image, ImageDraw, ImageFont
# from brother_ql.raster import BrotherQLRaster
# from brother_ql.devicedependent import models, label_type_specs, ENDLESS_LABEL, DIE_CUT_LABEL, ROUND_DIE_CUT_LABEL
# from brother_ql import BrotherQLError, BrotherQLUnsupportedCmd, BrotherQLUnknownModel
from brother_ql.backends import backend_factory
# from brother_ql.reader import interpret_response
title_text: str = 'Cameras'
list_text: str = "Wifi Outdoor \nWifi Indoor \nOther"
base_url: str = 'https://nc.torchtarget.biz/apps/files/?dir=/Inventory/'
qr_url: str = base_url + title_text
print(qr_url)
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=4,
border=4,
)
mypath: str = "tmp3.bmp"
mypath2: str = "tmp3.bin"
qr.add_data(qr_url)
qr.make(fit=True)
img = qr.make_image()
print(img.size[1], img.size[0])
x = img.size[1]
y = img.size[0]
newImage = Image.new('L', (x * 2, int(y + y // 4 + 1)), "white")
titleImage = Image.new('L', (x * 2, int(y // 4 + 1)), "white")
textImage = Image.new('L', (x, y), "white")
draw = ImageDraw.Draw(textImage)
draw.multiline_text((0, 10), list_text)
textImage.save("tmp2.bmp")
draw = ImageDraw.Draw(titleImage)
font = ImageFont.truetype("arial.ttf", int(y / 5))
draw.text((0, 0), title_text, font=font)
titleImage.save("tmp4.bmp")
newImage.paste(titleImage, (0, 0))
newImage.paste(img, (0, int(y // 4 + 1)))
newImage.save("tmp1.bmp")
newImage.paste(textImage, (x, int(y // 4 + 1)))
newImage.save("tmp3.bmp")
# 29x90 Codes 306x 991
qlr = brother_ql.BrotherQLRaster('QL-700')
qlr.exception_on_warning = True
brother_ql.create_label(qlr, newImage, '62')
fo = open(mypath2, 'wb')
fo.write(qlr.data)
fo.close()
be = backend_factory('pyusb')
list_available_devices = be['list_available_devices']
BrotherQLBackend = be['backend_class']
ad = list_available_devices()
for printer in ad:
print("HERE")
print(ad)
print(printer['identifier'])
string_descr = ad[0]['identifier']
print("Selecting first device %s" % string_descr)
printer = BrotherQLBackend(string_descr)
printer.write(qlr.data)