← back to Commercialrealestate

scripts/run-afternoon-report.sh

40 lines

#!/bin/zsh
# Daily 1pm SFV CRE update -> emails "additional listings since morning + red-hot opportunities"
# to steve-office + steve-personal via George. Wired to launchd com.steve.cre-afternoon-report (13:00 PT).
# Flow: snapshot current listing ids -> Browserbase/Crexi re-scrape (the ONLY paid step, ~$0.30-0.60/run)
#       -> Qwen re-rank (local/free) -> afternoon-report.js builds HTML + sends via George local /api/send.
export PATH="/usr/local/bin:/opt/homebrew/bin:$HOME/.npm-global/bin:$HOME/.claude/local:$PATH"
export NODE_PATH="$HOME/.claude/skills/browserbase/node_modules"
# Cost trim: the daily 1pm sweep navigates only the 5 densest in-budget SFV commercial cores
# (vs the weekly job's full 10-city sweep). refresh-listings.js keeps any SFV-wide listing it
# captures, so coverage stays broad; the Monday full sweep is the comprehensive backstop.
# Halves the Browserbase session length -> ~$0.15-0.30/run (~$4.50-9/mo). Tune freely.
export CC_NAV="Van Nuys,North Hollywood,Reseda,Northridge,Panorama City"
cd "$HOME/Projects/commercialrealestate" || exit 1
LOG=/tmp/cre-afternoon-report.log
echo "===== afternoon run $(date) =====" >> "$LOG"

# 1) Snapshot listing ids BEFORE the scrape so the report can diff "what's new since morning".
/opt/homebrew/bin/node -e '
  const fs=require("fs");
  const d=JSON.parse(fs.readFileSync("data/listings.json","utf8"));
  fs.writeFileSync("data/.pre-afternoon-ids.json", JSON.stringify({ at:new Date().toISOString(), ids:d.listings.map(l=>l.id) }));
  console.log("snapshot ids:", d.listings.length);
' >> "$LOG" 2>&1

# 2) Re-scrape Crexi (appends new in-band SFV listings, deduped). Non-fatal: if Browserbase is down we still
#    re-rank + report the red-hot deals on existing data.
/opt/homebrew/bin/node scripts/refresh-listings.js >> "$LOG" 2>&1 || echo "refresh-listings failed (continuing)" >> "$LOG"

# 3) Re-rank (local Qwen, cached -> fresh only for genuinely new listings).
/opt/homebrew/bin/node scripts/analyze.js >> "$LOG" 2>&1

# 4) Build the afternoon report HTML and email it to both recipients (self-contained send).
/opt/homebrew/bin/node scripts/afternoon-report.js >> "$LOG" 2>&1

# 5) Commit the day's data + report.
git -c user.email=steve@designerwallcoverings.com -c user.name="Steve" add -A >> "$LOG" 2>&1
git -c user.email=steve@designerwallcoverings.com -c user.name="Steve" commit -q -m "afternoon CRE update $(date +%Y-%m-%d)" >> "$LOG" 2>&1 || echo "nothing to commit" >> "$LOG"

echo "===== done $(date) =====" >> "$LOG"