Skip to content

Instantly share code, notes, and snippets.

@not7cd
Last active November 16, 2020 19:35
Show Gist options
  • Save not7cd/592f8989c1cc0f1ee22b94ffd186664c to your computer and use it in GitHub Desktop.
Save not7cd/592f8989c1cc0f1ee22b94ffd186664c to your computer and use it in GitHub Desktop.
"""
dots w159h119
"""
import sys
import sqlite3
from itertools import cycle
dpi = 203
w_dots = int(160*dpi/72)
h_dots = int(120*dpi/72)
label_rows = 4
h_row = h_dots // label_rows
h_offset = cycle(range(0, h_dots, h_row))
conn = sqlite3.connect('labels.db')
c = conn.cursor()
# Create table
c.execute('''CREATE TABLE IF NOT EXISTS labels
(id INTEGER PRIMARY KEY AUTOINCREMENT,
text TEXT,
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP)''')
buf=False
for no, line in enumerate(sys.stdin):
# TODO: strip to ASCII only
line = line.strip()
h0 = next(h_offset)
if no % 4 == 0:
print("N")
print("q"+str(w_dots))
buf=True
else:
print("LO", end="")
print(0,h0,w_dots,1, sep=",")
c.execute('INSERT INTO labels (text) VALUES (?)',
(line,))
id=c.lastrowid
# TODO: refactor do 3 lines, and max 60 chars
print("A", end="")
print(
10,h0+10,0,
4,
2 if len(line) < 10 else 1,
3 if len(line) < 20 else 2,
"N",'"{}"'.format(line[:20]), sep=",")
if len(line) >= 20:
print("A", end="")
print(
10,h0+10+h_row//2,0,
4,
1,1,
"N",'"{}"'.format(line[20:40]), sep=",")
print("B", end="")
print(
w_dots-154, h0+5, 0, # postition, rotation
"E80", 2, 6, # barcode settings
h_row-20, # height
"B", # human readable
'"{:07d}"'.format(id), # data 7 digit,
sep=",")
if (no+1) % 4 == 0:
print("P1")
buf=False
if buf:
print("P1")
conn.commit()
conn.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment