Skip to main content

Post to WeChat Moments via ADB automation

Project description

wechat-moments

PyPI version CI License: MIT Python 3.12+

Post to WeChat Moments via ADB automation. Controls an Android phone running WeChat using a deterministic FSM — no LLM required for UI interaction.

Requirements

  • Python 3.12+
  • Android phone with USB debugging enabled, WeChat installed

Note: ADBKeyboard is required for Chinese text input and will be installed automatically on first use.

Installation

pipx (recommended)

pipx install wechat-moments

uv tool

uv tool install wechat-moments

Homebrew (macOS)

brew tap vangie/tap
brew install wechat-moments

Development

git clone https://github.com/vangie/wechat-moments
cd wechat-moments
uv sync

Usage

CLI

# Check device connection
wx-pyq status

# Post with text only
wx-pyq post "今天天气真好"

# Post with images (local paths or URLs, max 9)
wx-pyq post "周末出游" -i photo1.jpg -i photo2.jpg

# Post without preview confirmation prompt
wx-pyq post "自动发布" -i photo.jpg --no-preview

# Collect FSM test fixtures (run once with phone connected)
wx-pyq collect-fixtures -o tests/fsm/fixtures/

# Clean up expired staging / archive dirs
wx-pyq cleanup

MCP Server (for OpenClaw)

wx-pyq-mcp

Exposes 4 tools:

Tool Description
prepare_post(text, images) Stage assets, generate preview image, return post_id
submit_post(post_id) Execute ADB flow and publish to Moments
get_device_status() Check ADB connection and app installation
take_screenshot() Capture current phone screen for debugging

Typical OpenClaw workflow:

prepare_post("text", ["image.jpg"]) 
  → returns { post_id, preview_path, ... }
  → show preview_path to user for confirmation (optional)
submit_post(post_id)
  → returns { status: "success", archive_path: "..." }

Architecture

CLI / MCP Server
      │
   preview.py   ← prepare_post: stage images, generate layout preview
      │
   submit.py    ← execute_submit: lock + FSM + archive + history
      │
  ┌───┴──────────────────────────────────┐
  │ UI FSM (poster.py)                   │  ← concurrent with ↓
  │ LAUNCH → DETECT_TAB → NAV_DISCOVER   │
  │ → OPEN_MOMENTS → [DISCARD_DIALOG]    │
  │ → SELECT_IMAGES → INPUT_TEXT → DONE  │
  └──────────────────────────────────────┘
  │ Image FSM (images.py, background thread)
  │ IDLE → PUSHING → SCANNING → READY → CLEANUP
      │
    adb.py   ← ADB commands (screenshot, tap, dump UI, push files)
    cv.py    ← tab detection, checkmark counting
    ime.py   ← ADBKeyboard Chinese text input

Device Profiles

UI coordinates are stored in profiles/<device_serial>.json. Huawei defaults are in profiles/huawei_default.json. Run wx-pyq calibrate to create a profile for a new device.

Data Directory

~/.local/share/wechat-moments/
├── history.jsonl        # append-only event log
├── submit.lock          # global mutex
├── staging/<post_id>/   # active/pending posts
└── archive/<post_id>/   # completed posts (preview + meta kept 30 days)

Testing

# Unit + FSM identify tests (no phone needed)
uv run pytest tests/unit/ tests/fsm/ -v

# End-to-end (phone required)
uv run pytest -m e2e

# Collect FSM fixtures from real device (run once)
wx-pyq collect-fixtures -o tests/fsm/fixtures/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wechat_moments-0.1.0.tar.gz (44.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wechat_moments-0.1.0-py3-none-any.whl (50.8 kB view details)

Uploaded Python 3

File details

Details for the file wechat_moments-0.1.0.tar.gz.

File metadata

  • Download URL: wechat_moments-0.1.0.tar.gz
  • Upload date:
  • Size: 44.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for wechat_moments-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9412f8d5eca2f7b127ecef968c3d833a6a2d5cc351a590e467b28d6ddfcc301e
MD5 1beb312851f849adcdd56b0e2c6b4de3
BLAKE2b-256 a6dbc7823575ae757e8e84d4f1db243c292f08326da086c1f9f4c702a2c193ae

See more details on using hashes here.

File details

Details for the file wechat_moments-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: wechat_moments-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 50.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for wechat_moments-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d39aaab77e5e4c4c98e3bc955a888a7559a179bf36660451db490952fb0a2e8a
MD5 f3130c6b375e6c94866b5b6286daa05d
BLAKE2b-256 99b4f07c6d89e92b7161b310a5cb17393deccc5a034f46ebc201a406d06d380e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page