Files
xhs_crawler/scripts/login_watcher.sh
T

50 lines
1.0 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
export DISPLAY=:99
DATA_DIR="/app/data"
REQ="${DATA_DIR}/.login_request.json"
STATUS="${DATA_DIR}/.login_status.json"
LOCK="${DATA_DIR}/.login_lock"
write_status () {
local state="$1"
local msg="$2"
local ts
ts="$(date -Iseconds)"
python - <<PY > "$STATUS"
import json
print(json.dumps({"state":"$state","msg":"$msg","ts":"$ts"}, ensure_ascii=False))
PY
}
echo "[login] watcher running, data_dir=${DATA_DIR}"
while true; do
if [ -f "$REQ" ]; then
if [ -f "$LOCK" ]; then
sleep 1
continue
fi
touch "$LOCK"
write_status "running" "login started. Open noVNC and finish XHS login."
set +e
python -c "from xhs_crawler_core import login_mode_auto; login_mode_auto('data/storage_state.json', headless=False)"
rc=$?
set -e
if [ $rc -eq 0 ]; then
write_status "success" "login finished. storage_state.json updated."
else
write_status "failed" "login failed (rc=${rc}). Check xhs-novnc logs."
fi
rm -f "$REQ"
rm -f "$LOCK"
fi
sleep 1
done