10 Commits
Author SHA1 Message Date
adamfandClaude Opus 5.5 0d4e2130a6 Add serve --local for using the web page on this machine
CI / test (3.10) (push) Successful in 1m24s
CI / test (3.12) (push) Successful in 1m5s
CI / test (3.13) (push) Successful in 1m3s
The page is unreachable without nginx, since every route but /healthz
needs the X-Receipt-Token header it adds. `serve --local` serves it
without a token instead: it only binds to a loopback address and answers
only requests whose Host is localhost, 127.0.0.1 or ::1, so another site
can't reach it by DNS rebinding. POSTs still need the page header.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-14 22:24:52 +00:00
adamfandClaude Opus 5.5 ba92f1fbda Add scheduled and event-driven printing with a new web UI
CI / test (3.10) (push) Successful in 1m20s
CI / test (3.12) (push) Successful in 1m49s
CI / test (3.13) (push) Successful in 1m5s
The web server now runs a scheduler over schedules kept in SQLite
(~/.local/share/receipt-maker, outside the clone). A schedule is a
trigger, a receipt made of blocks, and options:

- Triggers: once, recurring (rrule-based, DST-safe), sun times,
  reminders before calendar (ICS) events, RSS/JSON watchers, webhooks
  with per-schedule secrets.
- Blocks, rendered fresh as one job: templated notes ({date},
  {days_until:..}, rotating {choice}, trigger vars), QR, saved images,
  random image, calendar agenda, feed headlines, dividers.
- Rules: quiet hours (hold/skip/ignore), daily cap, pause, catch-up
  window for missed runs (never replayed), retries on connect failure
  only; a mid-job drop (new PrinterDropped) is never resent.

receipt.py renders through composable Blocks (render_note/image/qr are
wrappers, output unchanged). Print history persists, with Print again.
The page moves to web/ with Print (note/image/QR + paper preview),
Schedules (presets, editor with live preview and next runs), History
and Settings tabs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-23 23:58:26 +01:00
adamfandClaude Opus 5.5 597bace442 Send each print as one job, queue web prints, and harden deploys
CI / test (3.10) (push) Failing after 56s
CI / test (3.12) (push) Failing after 42s
CI / test (3.13) (push) Failing after 47s
Render every print to a complete ESC/POS payload (reset, content, cut)
and send it once over a fresh connection. Only the connect is retried,
so a link that drops mid-job can no longer print a partial image followed
by a full one, and no text size leaks into the next job. Prints are
capped at about 1 m of paper: tall images shrink, over-long notes are
refused.

Replace the argparse/stdout plumbing with PrinterConfig, InvalidJob and
PrinterUnavailable, and one run_command() dispatcher shared by the CLI
and TUI. Status now really connects; before, escpos's lazy open meant
the web server always reported the printer ready. Rendering with the
TM-T20II profile makes QR centering take effect.

The web server validates and renders jobs in the request (400 on bad
input), queues them for a single worker and answers 202; the page
long-polls /api/jobs/{id}, so no request outlives nginx's proxy timeout
while its job still prints. Status reports busy instead of waiting, and
jobs are logged with the nginx user.

update.sh tests new commits in a scratch worktree before touching the
live clone, and rolls back if /healthz doesn't answer after the restart.
The unit runs from the venv, and the web server defaults to localhost.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-23 22:07:58 +01:00
adamfandClaude Opus 5.5 30d1b83817 Add a note text size option; document the printer cabled to stppi
CI / test (3.10) (push) Failing after 47s
CI / test (3.12) (push) Failing after 54s
CI / test (3.13) (push) Failing after 48s
- note --size 1|2|3 magnifies the text and wraps to 48/24/16 columns,
  then resets the printer to normal size
- Web page gets a Size menu defaulting to Large; the API validates it
- README/CLAUDE.md: the printer has no Wi-Fi (UB-E04 needs an adapter),
  so it is cabled to stppi's eth0 at 192.168.192.168

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-23 21:48:54 +01:00
adamfandClaude Opus 5.5 f55b20fb82 Add a web server for printing from the site, deployed on stppi
CI / test (3.12) (push) Failing after 43s
CI / test (3.10) (push) Failing after 6m6s
CI / test (3.13) (push) Failing after 36s
`./receipt.py serve` (receipt_web.py, the new [web] extra) serves a page
for printing a note or an uploaded image. The site's nginx gates
/receipt/ on the admin session and proxies to it over Tailscale, adding
X-Receipt-Token; nothing but /healthz answers without it, and POSTs also
need X-Requested-With: receipt. Jobs run one at a time behind a lock
around run_action(), and uploads print from memory.

run_action(), _dispatch() and setup_network_quiet() move from the TUI to
receipt.py so the server doesn't need textual. --no-setup (needs_setup())
skips the sudo connect script everywhere it would run; serve always sets
it. cmd_print takes in-memory `data`.

deploy/ has the systemd user units. receipt-update.timer runs update.sh
every 5 minutes: it fast-forwards the clone from Gitea, runs the tests
and restarts receipt-web, rolling back if they fail.

Also included from earlier uncommitted work: the CI matrix moved to the
right place, connect_receipt.sh no longer re-parses CLI values in
bash -c, RECEIPT_PRINTER_IP/PORT are validated, pyusb is declared, the
ruff S rules are on, and the img/ cache and junk/ are no longer tracked.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-23 21:22:31 +01:00
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
adamfandClaude Fable 5 71686e8ad4 Add tests, TUI, packaging, and CI
CI / test (push) Failing after 6m11s
- receipt_tui.py: Textual terminal UI (tui subcommand), optional [tui] extra
- tests/: pytest suite for CLI and TUI using fakes; no hardware needed
- pyproject.toml: packaging with dev/tui extras, ruff config
- GitHub Actions CI running ruff and pytest
- Rename connect_recipt.sh -> connect_receipt.sh
- CLAUDE.md project instructions; README updates

Co-Authored-By: Claude Fable 5 <[email protected]>
2026-08-11 19:53:18 +01:00
adamf 573d8574a2 add more subcommands 2026-03-07 14:38:53 +00:00
adamf 5cdab2efcb removed scrap code 2025-11-18 16:07:55 +00:00
adamf 5a842158ad Initial commit 2025-11-14 22:47:27 +00:00