← back to Commercialrealestate

scripts/run-residential-report.sh

33 lines

#!/bin/bash
# run-residential-report.sh — build + email the LA County Residential Pulse (SFR + condo: just listed /
# in escrow / just sold / fell out) to steve-office + steve-personal. Local + free ($0).
# Scheduled 4x/day at :30 past (06:30/12:30/18:30/00:30) — AFTER the residential refresh (:00) finishes,
# so the report reflects the fresh sweep. launchd: com.steve.crcp-residential-report.
set -uo pipefail
cd "$HOME/Projects/commercialrealestate" || exit 1
export PATH="/usr/local/bin:/opt/homebrew/bin:$PATH"
LOG=tmp/residential-report.log
mkdir -p tmp
D="$(date +%Y-%m-%d)"
echo "===== [$(date '+%F %T')] residential report =====" >> "$LOG"

REPORT_DATE="$D" node scripts/residential-report.js > data/residential-report.html 2>>"$LOG"
BYTES=$(wc -c < data/residential-report.html 2>/dev/null || echo 0)
if [ "$BYTES" -lt 2000 ]; then
  echo "[$(date '+%T')] ABORT — report build too small ($BYTES bytes); not sending." >> "$LOG"; exit 2
fi

. "$HOME/.claude/skills/_shared/george-send.sh"; george_resolve_cfg
TO="${RESIDENTIAL_REPORT_TO:-steve@designerwallcoverings.com, steveabramsdesigns@gmail.com}"
# Pull the two headline counts into the subject (nice-to-have; falls back gracefully).
ESC=$(grep -oE 'color:#d29922">[0-9,]+' data/residential-report.html | head -1 | grep -oE '[0-9,]+' || echo '')
NEW=$(grep -oE 'color:#3fb950">[0-9,]+' data/residential-report.html | head -1 | grep -oE '[0-9,]+' || echo '')
SUBJ="🏠 LA Residential Pulse — ${ESC:-?} in escrow, ${NEW:-?} just listed ($D)"

jq -Rn --arg account steve-office --arg to "$TO" --arg subject "$SUBJ" --rawfile body data/residential-report.html \
  '{account:$account,to:$to,subject:$subject,body:$body}' > tmp/res-report-payload.json
RESP="$(curl -sS --max-time 45 "$GEORGE_URL$GEORGE_PFX/api/send" \
  -H "Authorization: Basic $GEORGE_BASIC_AUTH" -H "Content-Type: application/json" --data @tmp/res-report-payload.json)"
echo "$RESP" | grep -q '"success":true' && echo "[$(date '+%T')] sent -> $TO" >> "$LOG" \
  || echo "[$(date '+%T')] SEND FAILED: $RESP" >> "$LOG"