fix(session): pass REDDIT_SESSION_FILE env to post.py subprocess; fix status check path
refresh_session() was spawning post.py --login without the REDDIT_SESSION_FILE env
var, so Playwright wrote the refreshed session to the legacy session.json default
instead of sessions/alan_reddit.json. The poster then read a stale file and
failed with 'Playwright re-login failed'.
- Add os import; pass env={...os.environ, REDDIT_SESSION_FILE: str(session_file)}
to subprocess.run so post.py writes to the correct per-account path
- manage.sh status now checks sessions/alan_reddit.json (canonical) not session.json
- Replace session.json with a symlink to sessions/alan_reddit.json for legacy compat
This commit is contained in:
parent
92799b05f9
commit
15779e3114
2 changed files with 6 additions and 4 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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 ""
|
||||
|
|
|
|||
Loading…
Reference in a new issue