# We-MP-RSS Health Check

## Script: `~/.hermes/scripts/check_werss_login.py`

Checks login status by reading `werss:login:status` from Redis directly.
Returns exit code 0 if logged in, 1 if not.

On failure, sends 企微群 webhook alert. Webhook key is embedded in the script.

**Important:** The script uses an explicit venv Python shebang:
```
#!/home/agentuser/project/we-mp-rss-main源文件/we-mp-rss-main/venv/bin/python3
```
This is required because the cron environment's `#!/usr/bin/env python3` resolves to system Python, which lacks venv-installed packages (`redis`, `requests`). Without the explicit venv path, the script fails with `ModuleNotFoundError: No module named 'redis'`.

### Running manually

```bash
~/project/we-mp-rss-main源文件/we-mp-rss-main/venv/bin/python3 ~/.hermes/scripts/check_werss_login.py
```

The explicit shebang means you can also run it directly:
```bash
~/.hermes/scripts/check_werss_login.py
```

### Why Redis, not API

`/auth/qr/status` reads `WeChat_api._islogin` — an in-memory Python instance variable.
After service restart, it resets to `False` even when valid WeChat cookies exist in Redis.
Redis `werss:login:status` is the source of truth.

### How login flow works

1. User opens https://rss.gdcjgk.net → scans QR code
2. Backend polls WeChat MP → on success calls `_handle_login_success()`
3. Extracts cookies + token → stores to Redis keys:
   - `werss:login:status` = "1"
   - `werss:token:data` = JSON with cookie + token
4. Article fetcher reads `werss:token:data` for WeChat MP API calls

### Common failure mode

After a service restart:
- Redis still has `werss:login:status = "1"` and token data
- But `WeChat_api._islogin = False` (in-memory reset)
- `/qr/status` reports "not logged in" — **false alarm**
- Article fetching still works (reads from Redis)

### Cron shebang pitfall

When the cron scheduler runs a script via the `script` field, it strips most environment variables.
`#!/usr/bin/env python3` resolves to **system Python** (`/usr/bin/python3`), not the project venv.
System Python has only stdlib — no `redis`, `requests`, or any pip-installed package.
**Always use an explicit venv path in cron-bound Python scripts.**
