adamfandClaude Code e333d6729f Fix security, robustness, and config-drift issues
- Close printer handles (contextlib.closing) in CLI and TUI
- Whitelist 4chan image extensions + numeric tim (path traversal)
- Cap downloads at 16 MB
- clean: unlink instead of rmtree, cover legacy dir, add -y flag
- TUI: escape captured output as rich Text; propagate failure exit code
- Pass --ip/--port through to connect_receipt.sh via env
- Fix double-space textln calls
- CI matrix 3.10/3.12/3.13
- pytest pythonpath so tests run without editable install
- Print retry narrowed to OSError/escpos errors

Co-Authored-By: Claude Code <[email protected]>
2026-09-22 22:20:51 +01:00
2025-11-14 22:47:27 +00:00
2025-11-14 22:47:27 +00:00
2025-11-14 22:47:27 +00:00
2026-08-11 19:53:18 +01:00
2026-08-11 19:53:18 +01:00
2026-08-11 19:53:18 +01:00

Receipt Maker

Prints images, text notes, and QR codes to an Epson TM-T20II thermal receipt printer, including random images from 4chan's /bant/ board.

How it works

  1. connect_receipt.sh — brings up the USB Ethernet interface, assigns 192.168.192.10/24, and waits until the printer at 192.168.192.168:9100 is reachable
  2. receipt.py — CLI with subcommands; images are resized in memory to the printer's full 576px width before printing

The CLI runs the connect script automatically before printing (unless --usb is used).

Requirements

  • Python 3.10+
  • python-escpos, Pillow, requests (see pyproject.toml)
  • textual (optional, only for the tui subcommand; pip install '.[tui]')
  • Epson TM-T20II connected via a USB-to-Ethernet adapter (or directly over USB with --usb)

Install the dependencies (or pip install . to also get a receipt command on your PATH):

pip install python-escpos Pillow requests

Usage

# Print a random image from /bant/ (optionally more than one)
./receipt.py image
./receipt.py image 3

# Print a text note (from an argument or stdin), word-wrapped to 48 columns
./receipt.py note "your message here"
fortune | ./receipt.py note
./receipt.py note -t "with a date/time header"

# Print a local image (with optional caption)
./receipt.py print path/to/image.jpg
./receipt.py print path/to/image.jpg "optional caption"

# Print a QR code (with optional caption)
./receipt.py qr "https://example.com" "scan me"

# Reprint a cached image (most recent, or by name from `list`)
./receipt.py reprint
./receipt.py reprint 1783716801701399

# Check the printer is reachable
./receipt.py status

# List or delete the downloaded image cache
./receipt.py list
./receipt.py clean

# Open the interactive terminal UI (needs `pip install textual`)
./receipt.py tui

# Use a direct USB connection instead of Ethernet
./receipt.py --usb note "hello"

# Point at a different printer (or set RECEIPT_PRINTER_IP / RECEIPT_PRINTER_PORT)
./receipt.py --ip 10.0.0.5 --port 9100 status

Images are prepared for thermal output automatically: transparency is composited onto white, then the image is resized to full width, autocontrast-stretched, and Floyd-Steinberg dithered.

Development

pip install -e '.[dev]'
pytest          # run the tests
ruff check .    # lint

Both checks also run in CI on every push and pull request (.github/workflows/ci.yml).

Files

  • receipt.py — main script
  • receipt_tui.py — Textual terminal UI (./receipt.py tui)
  • connect_receipt.sh — network setup for the USB Ethernet adapter
  • tests/ — pytest suite for the CLI and TUI (no printer or network needed)
  • img/ — downloaded images cache (gitignored; clear with ./receipt.py clean)
S
Description
No description provided
Readme
12 MiB
Languages
Python 69.3%
JavaScript 24.4%
CSS 4.8%
Shell 1.3%
HTML 0.2%