What this prompt does
This prompt casts the model as a senior Python data engineer and asks for a cron-friendly script that runs daily and emails a KPI report, returning complete runnable code rather than pseudocode. It lays out six deliverables: a query/extract step that pulls the window implied by the schedule with a clear date boundary, KPI computation in Pandas with day-over-day deltas, matplotlib charts rendered to PNG and embedded inline via CID plus an HTML summary table, an SMTP send with TLS, a plaintext fallback part, and retry on transient failure, all secrets and config via environment variables with a sample .env, and structured logging with a non-zero exit code on failure for cron alerting. The structure works because it makes the job fail loudly, which is what makes a daily email a trustworthy monitor.
Four variables drive it. [data_source] names where data comes from, like a PostgreSQL events table. [kpis] lists the metrics to compute — DAU, WAU, conversion rate, revenue — each getting a day-over-day delta. [recipients] sets who receives the email. [schedule] defines cadence and window, such as daily at 07:00 covering yesterday, which drives the date boundary in the extract step. Deliverable six is the load-bearing part: a silent broken cron is worse than no report, so the script must exit non-zero on failure so the scheduler can alert.
When to use it
- A stakeholder wants daily numbers in their inbox without building a full dashboard.
- You need a cron-friendly script that pulls data, computes KPIs, and emails a report.
- Day-over-day deltas and inline charts matter for the report's readability.
- You want secrets handled via environment variables with a documented sample .env.
- Failure must be loud — a non-zero exit code so a broken cron job alerts you.
- You need the full script plus the crontab line to schedule it.
Example output
Expect the full script plus the crontab line to schedule it. An extract step pulls the window implied by [schedule] with a clear date boundary from [data_source]; Pandas computes [kpis] with day-over-day deltas; matplotlib renders charts to PNG embedded inline via CID alongside an HTML summary table; an SMTP send to [recipients] uses TLS with a plaintext fallback and retry on transient failure; config flows through environment variables documented in a sample .env; and structured logging plus a non-zero exit on failure enables cron alerting. It is complete, runnable code you adapt to your environment.
Pro tips
- Be specific in
[data_source](table or query) so the extract step targets the right data with a correct date boundary. - List
[kpis]precisely; each one gets a day-over-day delta, so vague metrics produce vague computations. - Align
[schedule]cadence and window carefully, since it drives the date boundary the extract uses. - Make the job fail loudly with a non-zero exit; a silent broken cron is worse than no report at all.
- Keep all secrets in environment variables per the sample .env rather than hardcoding SMTP credentials.
- If charts render poorly, re-run asking for specific chart types per KPI and inline CID embedding details.