Add scheduled and event-driven printing with a new web UI
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]>
This commit is contained in:
@@ -113,6 +113,24 @@ sudo nmcli con add type ethernet ifname eth0 con-name receipt-printer connection
|
||||
|
||||
Jobs are checked and rendered when submitted (a bad note or image is rejected straight away), then queued and printed one at a time. The page shows each job as queued, printing, then done or failed, and the status pill shows "printer busy" during a print rather than waiting for it. Each job is logged to the service's journal with the signed-in user nginx forwards. If the server machine is off, the site shows "printer machine offline".
|
||||
|
||||
### Schedules
|
||||
|
||||
The page has four tabs: **Print** (note, image or QR code, with a preview of the paper), **Schedules**, **History** and **Settings**. A schedule is *when* + *what* + *options*:
|
||||
|
||||
- **When**: once; repeating (every N days/weeks/months/years, chosen weekdays, "first weekday of the month", several times a day, or a custom RRULE); at sunrise/sunset/dawn/dusk ± minutes; N minutes before each event in a calendar; when an RSS feed gets new items or a JSON value changes/crosses a threshold; or when its webhook is called.
|
||||
- **What**: a receipt built from blocks: notes (with `{date}`, `{time}`, `{days_until:12-25}`, `{choice}` from a rotating list, and `{event.title}`, `{item.title}`, `{payload.text}`… from the trigger), QR codes, saved images, a random /bant/ image, a calendar agenda, feed headlines and dividers. It is rendered fresh each time it fires, as one job.
|
||||
- **Options**: what to do in quiet hours (wait, skip, print anyway), skip when the agenda/headlines are empty, how late a missed run may still print (after a restart; later ones are logged as missed, never replayed), and retries if the printer is off (a job that dropped mid-print is never retried).
|
||||
|
||||
Settings hold the time zone, location (for sun times), quiet hours, a daily cap on automatic prints, a pause switch (holiday mode), and saved calendars (ICS, e.g. Google Calendar's secret iCal address) and feeds. Everything lives in SQLite at `~/.local/share/receipt-maker/receipt.db` (`RECEIPT_DATA_DIR` to move it), outside the clone, so deploys and rollbacks leave it alone.
|
||||
|
||||
**Webhooks**: a webhook schedule gets a URL (`…/receipt/hook/<id>`) and a secret, shown once. Call it with the secret in `X-Hook-Secret` or `?key=`; JSON fields become `{payload.…}` and a plain-text body is `{payload.text}`:
|
||||
|
||||
```bash
|
||||
curl -X POST https://www.adam-french.co.uk/receipt/hook/<id> -H 'X-Hook-Secret: <secret>' -d 'Buy milk'
|
||||
```
|
||||
|
||||
The site's admin login would block other services, so nginx on stpvm needs a `location /receipt/hook/` without the `auth_request` (still adding `X-Receipt-Token`, ideally with `limit_req` and `client_max_body_size 64k`). Until then webhooks work over Tailscale only.
|
||||
|
||||
### Automatic updates
|
||||
|
||||
`receipt-update.timer` runs `deploy/update.sh` every 5 minutes. When `master` on Gitea has moved, the script:
|
||||
@@ -139,6 +157,8 @@ Both checks also run in CI on every push, on Python 3.10, 3.12 and 3.13. Gitea A
|
||||
- `receipt.py` — main script
|
||||
- `receipt_tui.py` — Textual terminal UI (`./receipt.py tui`)
|
||||
- `receipt_web.py` — web server for printing from the site (`./receipt.py serve`)
|
||||
- `receipt_store.py`, `receipt_models.py`, `receipt_triggers.py`, `receipt_sources.py`, `receipt_content.py`, `receipt_scheduler.py` — schedules (run by `serve`)
|
||||
- `web/` — the web page
|
||||
- `deploy/receipt-web.service` — systemd user unit for the web server
|
||||
- `deploy/update.sh`, `deploy/receipt-update.{service,timer}` — automatic updates from Gitea
|
||||
- `connect_receipt.sh` — network setup for the USB Ethernet adapter
|
||||
|
||||
Reference in New Issue
Block a user