#!/bin/bash
# [2026-10-24] waiter: after the 2016-18 flow download and the Star lists are done -> download the Star flow (re-run until done:
# the downloader stops in market hours, this loop restarts it after the close).
cd /var/www/screener/trade/reports/ev3
until grep -q "FLOW_TICK_DONE" flow_10y.log && grep -q "STARLISTS_DONE" star_lists.log; do sleep 60; done
until grep -q "STAR_FLOW_DONE" star_flow.log 2>/dev/null; do
  H=$(TZ=America/New_York date +%H%M); D=$(TZ=America/New_York date +%u)
  if [ "$D" -le 5 ] && [ "$H" -ge 0910 ] && [ "$H" -lt 1605 ]; then sleep 300; continue; fi
  nice -n 19 python3 star_flow.py >> star_flow.log 2>&1
  sleep 60
done
echo "STAR_QUEUE_DONE $(date)" >> star_flow.log
