Skip to content

Repository files navigation

Weibo Super Topic Auto Check-in

English | 繁體中文 | 简体中文

Python Platform Scheduler

Description

Automatically checks in to all followed Weibo super topics every day, with no manual intervention required.

The system uses Playwright to scan a QR code locally and obtain a login cookie, which is stored in GCS. Each day, Cloud Scheduler triggers a Cloud Functions deployment that reads the cookie, fetches the list of followed super topics, checks in to each one, and sends an email report of the daily results and cookie health. After each run, any refreshed cookies issued by the server (via Set-Cookie) are merged back into GCS — mimicking a normal browser's continuous cookie renewal to keep the session alive.

System Environment

Item Description
Platform GCP Cloud Functions (2nd gen, HTTP trigger, region: asia-east1)
Schedule Cloud Scheduler, daily at 09:00 Taiwan time (cron 0 9 * * *)
Language Python 3.11
Storage Google Cloud Storage (stores login cookie)
Notifications Gmail SMTP
Login Tool Playwright (local use only)

Installation

1. Get the code and create a virtual environment

git clone <repo-url>
cd weibo-checkin
python -m venv myenv
myenv\Scripts\activate   # Windows

2. Install dependencies

Local development (includes Playwright, used for login):

pip install -r requirements-local.txt
playwright install chromium

Cloud deployment (without Playwright):

pip install -r requirements.txt

3. Configure environment variables

Copy .env.example to .env and fill in real values:

cp .env.example .env
Variable Description
GCS_BUCKET_NAME GCS bucket name for storing the cookie
SMTP_USERNAME Gmail account
SMTP_PASSWORD Gmail app password
EMAIL_SENDER Sender email address
EMAIL_RECEIVER Recipient email address
ENV Runtime environment (local or gcp)

Quick Start

  1. Log in locally and upload the cookie (first run, or when the cookie expires)

    python auth.py --checkin

    This opens a browser showing a QR code. Scan it with the Weibo app to log in, the cookie is automatically uploaded to GCS, and today's check-in runs immediately.

    You can also double-click relogin.bat (or the "Weibo Re-login" desktop shortcut) to do this with one click. This prevents a missed check-in on the day you re-login.

  2. Deploy to Cloud Functions

    gcloud functions deploy weibo-checkin \
      --gen2 \
      --runtime=python311 \
      --region=asia-east1 \
      --source=. \
      --entry-point=run \
      --trigger-http \
      --no-allow-unauthenticated
  3. Set up the daily schedule

    gcloud scheduler jobs create http weibo-checkin-daily \
      --schedule="0 9 * * *" \
      --time-zone="Asia/Taipei" \
      --uri="https://asia-east1-weibo-checkin.cloudfunctions.net/weibo-checkin" \
      --http-method=POST \
      --oidc-service-account-email=<service-account-email>
  4. Manually test the full flow locally

    python -c "import main; main.run(None)"

Workflow

1. Run auth.py --checkin locally
   - Playwright opens a browser -> scan QR code to log in to Weibo
   - Obtain the full cookie (with domain info) -> upload to GCS
   - Immediately run today's check-in (prevents missed check-in on re-login day)

2. Cloud Scheduler triggers Cloud Functions daily at 09:00 (Taiwan time)

3. Cloud Functions (main.py) runs
   - Read the cookie from GCS and verify it is valid
       - If invalid -> send a "cookie expired" notification and stop
   - Fetch the "followed super topics" list via weibo_api.py (auto pagination)
   - Send a check-in request for each topic (random 3-8s delay, mimics human behavior)
   - Merge refreshed cookies from the server back into GCS (cookie renewal)
   - Write each check-in result to Cloud Logging
   - If any check-ins failed -> send a "failure details" notification
   - Send a "daily summary" email (date, success/failure counts)

Architecture

weibo-checkin/
├── main.py                   # Cloud Functions entry point (HTTP trigger)
├── auth.py                   # Cookie management (Playwright login, GCS read/write, validation, renewal write-back)
├── weibo_api.py              # Weibo API wrapper (paginated topic list, check-in request, HTTP headers)
├── checkin.py                # Main flow orchestrator (combines auth + weibo_api, controls random delays)
├── notifier.py               # Gmail SMTP email notifications
├── config.py                 # Centralized config constants (endpoints, bucket, delay range, recipients)
├── requirements.txt          # Cloud Functions deployment dependencies (no playwright)
├── requirements-local.txt    # Local dev dependencies (includes playwright, used by auth.py)
├── .gcloudignore             # Excludes myenv/, .env, test files, etc. from deployment
├── relogin.bat               # One-click local re-login shortcut (with desktop shortcut); also runs today's check-in after login
├── .env                      # Actual environment variables (not in git)
└── .env.example              # Environment variable template (no real values)

Component Diagram

                ┌────────────┐
   (local)      │  auth.py   │── Playwright QR code login
                └─────┬──────┘
                      │ writes cookie
                      ▼
                ┌────────────┐
                │    GCS     │  weibo-checkin-bucket
                └─────┬──────┘
                      │ reads cookie (refreshed cookies written back after each run)
                      ▼
 Cloud Scheduler ──▶ main.py (Cloud Functions)
   (daily 09:00)       │
                       ├─▶ auth.verify_cookie()
                       ├─▶ checkin.run_checkin()
                       │     └─▶ weibo_api.py (topic list + check-in API)
                       ├─▶ auth.persist_refreshed_cookies() (cookie renewal → GCS)
                       ├─▶ Cloud Logging (per check-in record)
                       └─▶ notifier.py ──▶ Gmail SMTP ──▶ Email notification

Constraints & Notes

  • No username/password login (Weibo restriction); QR code login only
  • The cookie is persisted in GCS and must not be committed to git
  • Check-in requests mimic human behavior (random delays, browser-like headers) to reduce bot detection risk
  • An expired cookie requires a manual re-scan; the system detects this automatically and sends an email notification
  • Cookie renewal (added 2026-07): after each daily run, refreshed cookies issued by the server via Set-Cookie are merged back into GCS, mimicking a normal browser's continuous renewal to avoid the observed fixed 7-day expiry (under observation)
  • The Cloud Function is deployed with --no-allow-unauthenticated, so only a service account with invoker permission (Cloud Scheduler via OIDC token) can call it
  • On Windows, tzdata must be installed locally (pip install -r requirements-local.txt); Python's zoneinfo has no built-in timezone database on Windows

See SPEC.md for more details.

About

每天自动签到所有关注的微博超话 | 一键签到微博超话 | GCP Auto check-in for all followed Weibo super topics

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages