Print lamp ID labels on the Brother QL-820NWB

label_printer.py renders a DK-11221 23x23 mm label (QR code linking
to the lamp's buildfor.life page plus the ID) and sends it over the
network backend (brother-ql-next). The station prints two after each
successful measurement, one for the box and one for the lamp; printer
failures never lose a run, and any lamp can be reprinted with
uv run label_printer.py <ID>. Printer address via HPCS_LABEL_PRINTER
or --printer.
This commit is contained in:
2026-07-09 18:15:01 +07:00
parent 7ef2960254
commit 719ddcf04a
4 changed files with 141 additions and 1 deletions
+24
View File
@@ -31,6 +31,10 @@ supports unbranded lamps without any barcode.
website picks it up automatically (data-driven device list plus the
auto-bump deploy); an .md page in the web repo is only ever needed
for photos, where-to-buy links, or notes.
6. Two ID labels (QR to the lamp's page + the ID, DK-11221 23x23 mm)
print on the Brother QL-820NWB: one for the box, one for the lamp.
Configure the printer via HPCS_LABEL_PRINTER or --printer; reprint
any lamp later with `uv run label_printer.py L0006`.
Usage:
uv run lamp_station.py # defaults below
@@ -40,6 +44,7 @@ Usage:
import argparse
import json
import os
import re
import subprocess
import sys
@@ -304,6 +309,20 @@ def measure_one(new_id, ean, lamps, args, data_repo, existing_id=None):
print(" The lamp publishes automatically (auto-bump deploy); add an .md under")
print(" src/content/comparisons/lamps/ only for photos, buy links, or notes.")
# Two ID labels on the QL-820NWB: one for the box, one for the lamp.
if not args.no_labels:
if args.printer:
try:
from label_printer import print_labels
print_labels(lamp_id, args.printer, copies=2)
print(f" Printed 2 ID labels for {lamp_id}.")
except Exception as e: # noqa: BLE001 — a printer problem must not lose the run
print(f" Label printing failed ({e}); reprint later with:")
print(f" uv run label_printer.py {lamp_id}")
else:
print(f" (no label printer configured; set HPCS_LABEL_PRINTER or use --printer,")
print(f" reprint later with: uv run label_printer.py {lamp_id})")
def main():
parser = argparse.ArgumentParser(description="Barcode-driven lamp measurement station")
@@ -320,6 +339,11 @@ def main():
help="Write the bundle but skip git entirely")
parser.add_argument("--no-push", action="store_true",
help="Commit locally but do not push")
parser.add_argument("--printer", default=os.environ.get("HPCS_LABEL_PRINTER", ""),
help="QL-820NWB address, e.g. tcp://192.168.1.50 "
"(default: HPCS_LABEL_PRINTER env)")
parser.add_argument("--no-labels", action="store_true",
help="Skip printing the two ID labels after each lamp")
args = parser.parse_args()
data_repo = Path(args.data_repo)