#!/usr/bin/env bash
# Real demos for P092 "Python Automation: Full Tutorial for Beginners". Runs on the spare render Mac's Docker
# (or render01). One stock Ubuntu 24.04 container stands in for Ana's laptop (lab/Dockerfile). uv, every Python
# package and Playwright's Chromium are installed on camera, from the internet, as on any laptop.
# Off-screen, inside the same container, stand-ins for the outside world: her supplier's API and web portal
# (lab/supplier.py on 127.0.0.1:8000), a test mail server that prints what it receives instead of delivering it
# (aiosmtpd on 127.0.0.1:1025, log in /srv/mail/inbox.log), her Downloads folder (lab/make_files.py) and the
# cron daemon. Ana's scripts are lab/shop-bot/*.py, copied into the project uv makes on camera ("she wrote them
# in her editor"). Every command shown is typed into a real interactive bash in a pty (demo_driver.py).
set -euo pipefail
cd "$(dirname "$0")"
P=ce-p092
cleanup() { docker rm -f $P-laptop >/dev/null 2>&1 || true; }
cleanup
[ -n "${KEEP:-}" ] || trap cleanup EXIT
docker build -q -t $P-laptop lab >/dev/null
docker run -d --name $P-laptop --hostname laptop $P-laptop sleep infinity >/dev/null
docker exec -d $P-laptop python3 /srv/supplier/supplier.py
docker exec -d -u ana $P-laptop sh -c \
  'python3 -u -m aiosmtpd -n -l 127.0.0.1:1025 -c aiosmtpd.handlers.Debugging > /srv/mail/inbox.log 2>&1'
docker exec -u ana $P-laptop python3 /srv/supplier/make_files.py /home/ana
docker exec $P-laptop cron
sleep 1
python3 - "$P" < demo_driver.py
