diff --git a/app/services/reddit/session.py b/app/services/reddit/session.py index 12b6adf..640f084 100644 --- a/app/services/reddit/session.py +++ b/app/services/reddit/session.py @@ -7,6 +7,7 @@ Session cookies are stored in a JSON file and refreshed automatically when stale from __future__ import annotations import json +import os import subprocess import sys import time @@ -33,7 +34,7 @@ def session_is_valid(session_file: Path | None = None) -> bool: def refresh_session(session_file: Path | None = None) -> None: - """Re-login via Playwright (xvfb-run) and overwrite session.json.""" + """Re-login via Playwright (xvfb-run) and overwrite the session file.""" if session_file is None: session_file = Path(get_settings().reddit_session_file) session_file.parent.mkdir(parents=True, exist_ok=True) @@ -41,6 +42,7 @@ def refresh_session(session_file: Path | None = None) -> None: result = subprocess.run( ["xvfb-run", "--auto-servernum", sys.executable, str(_POST_SCRIPT), "--login"], cwd=str(_POST_SCRIPT.parent), + env={**os.environ, "REDDIT_SESSION_FILE": str(session_file)}, timeout=120, ) if result.returncode != 0: diff --git a/manage.sh b/manage.sh index 8619e4f..dc703f6 100755 --- a/manage.sh +++ b/manage.sh @@ -196,8 +196,8 @@ case "$cmd" in info " Scheduler ${sched} scheduled" fi - # Session age - SESSION_FILE="${DATA_DIR}/session.json" + # Session age — check the canonical per-account file, not the legacy session.json + SESSION_FILE="${DATA_DIR}/sessions/alan_reddit.json" if [[ -f "$SESSION_FILE" ]]; then age_h=$(python3 -c "import time,os; print(f\"{(time.time()-os.path.getmtime('$SESSION_FILE'))/3600:.1f}h\")" 2>/dev/null || echo "?") if python3 -c "import time,os; exit(0 if (time.time()-os.path.getmtime('$SESSION_FILE'))/3600 < 12 else 1)" 2>/dev/null; then @@ -206,7 +206,7 @@ case "$cmd" in warn " Session ${age_h} old (stale — run: ./manage.sh login)" fi else - warn " Session no session.json — run: ./manage.sh login" + warn " Session no session file — run: ./manage.sh login" fi echo ""