Template¶
TOML template engine for the GoojPrt PT-210.
Lets callers define a print job as a list of items in a .toml file,
with dynamic variables substituted before printing. A job is printed
by calling print_template() — the function loads the file,
expands variables, connects over BLE and issues the matching SDK calls.
Supported item types (see print_template() for the full dispatch
table): text_image, text, pdf417, qr, line, feed,
cut, grid, ekg. Unknown types produce a warning on stdout
and are skipped.
- goojprt.template.build_vars(extra: dict[str, str] | None = None) dict[str, str][source]¶
Build the built-in variable table (date, time, expiries, passwords).
Time-related variables (values reflect “now” at call time):
{{date}}— today’s date (02.04.2026){{date_iso}}— ISO date (2026-04-02){{time}}— current time (14:35){{time_full}}— current time with seconds{{datetime}}— date + time{{weekday}}— Czech weekday name (Středa){{week}}— ISO week number{{expire_1h}}— time + 1 hour{{expire_2h}}— time + 2 hours{{expire_4h}}— time + 4 hours{{expire_24h}}— date + time in 24 hours
Passwords (generated once, identical inside a single template run):
{{password_8}}— 8 characters{{password_12}}— 12 characters{{password_16}}— 16 characters
- Parameters:
extra – User-supplied variables (e.g. from the CLI
--varflag). They override built-ins when names collide.
- async goojprt.template.print_template(address: str, path: str, extra_vars: dict[str, str] | None = None) None[source]¶
Load a TOML template, substitute variables, connect via BLE and print.
Supported item types:
text_image,text,pdf417,qr,line,feed,cut,grid,ekg. Unknown types print a warning on stdout and are skipped.- Parameters:
address – Bluetooth address / UUID of the printer.
path – Filesystem path to a
.tomltemplate.extra_vars – Additional variables (e.g.
--var name=Filip).
- goojprt.template.random_password(length: int) str[source]¶
Generate a human-readable random password.
Uses
secrets.choice()and excludes characters that can be confused visually (0vsO,1vslvsI).- Parameters:
length – Desired password length in characters.