#!/bin/sh
# [2026-11-02] nightly: gzip the bots' decision logs older than 7 days (each bot writes ~225 MB/day; gzip ~7x smaller; gunzip restores).
# simulate.py / reports/day_pages.py / reports/agen/day_report.py read the .gz files directly.
# crontab line (add with: crontab -e):
# 30 18 * * 1-5 /usr/bin/flock -n /tmp/compress_logs.lock /bin/sh /var/www/screener/trade/tools/compress_old_logs.sh >> /var/www/screener/trade/logs/compress_old_logs.log 2>&1
CUT=$(date -d "7 days ago" +%F)
for d in /var/www/screener/trade/data/decisions /var/www/screener/premarket/data/decisions; do
  for f in "$d"/20*.jsonl; do
    [ -f "$f" ] || continue
    b=$(basename "$f" .jsonl); [ "$b" \< "$CUT" ] && nice -n 15 gzip -6 "$f"
  done
done
date; df -h / | tail -1
