Skip to main content

wechat-auto-publish

把写好的 Markdown 文章排版成公众号样式,一键推到微信公众号草稿箱。

快速开始(Hello World)

方式一:对话式自动生成并发布

复制下面这段,粘贴到豆包新会话里:

开启一个全新的会话,严格执行下面的指令。

# 公众号自动发文 · 执行提示词

1. **文章生成**:严格按内容生成提示词执行
   - 内容生成提示词:https://github.com/baiyigali/opp_radar/blob/main/prompts/dev.md (可换成你自己的)
   - 输出目录:~/articles/wechat/ (可换成你自己的,平铺不建子文件夹)

2. **发布**:严格按发布流水线执行
   - 发布流水线:https://github.com/baiyigali/wechat-auto-publish/blob/main/prompts/pipeline.md
   - appid:(填你自己的公众号App ID)
   - secret:(填你自己的公众号app secret)
   - author:(填你自己的文章作者)

3. **完成后报告**:文章标题、主名、发到哪个账号、草稿 media_id,
   以及输出目录下本次生成的文件清单;遇到错误原样报告。

方式二:命令行手动发布已有文章

# 安装
pip install wechat-auto-publish

# 把现成的 .md + 封面推到草稿箱
wechat-auto-publish draft "文章.md" "封面.png" "文章标题" \
  --appid 你的AppID --secret 你的AppSecret --author 作者名
# digest 摘要可省略,微信会自动生成

它做了什么

opp-radar          →  生成文章(.md + 封面 .png)
wechat-formatter   →  .md 渲染成公众号内联样式 HTML
wechat-publish     →  HTML + 封面推到公众号草稿箱
组件 仓库 / 包 职责
生成 opp_radar 机会雷达,按领域提示词产出渠道无关的文章
排版 wechat-formatter Markdown → 科技风经典蓝 HTML
发布 wechat-publish 草稿箱接口,图片自动转存微信 CDN

换领域、换排版主题、换发布渠道时,只在这一层换组件,不改上游。

安装

二选一:

A. 从 PyPI 安装(已发布后):

pip install wechat-auto-publish

B. 本地 clone 后安装(开发或未发布时):

git clone https://github.com/baiyigali/wechat-auto-publish.git
cd wechat-auto-publish
pip install -e .

依赖三个上游包(见 pyproject.toml)。

配置

复制 config.example.json 为 config.json,填入公众号凭据。支持多账号:default 指定默认号,accounts 下可放多个公众号;发指定号时命令加 --account <账号名>。config.json 已 gitignore,不进版本库。

用法

命令行:把一篇已写好的文章推到草稿箱

wechat-auto-publish draft "文章.md" "封面.png" "标题" [摘要]

摘要可省略,微信会自动生成。

编排:生成 + 发布一条龙

给 AI agent 说:"按 prompts/pipeline.md 跑一期"。它会先读"生成"那一环的领域提示词产出文章,再调用本仓库推到草稿箱。生成环节以 opp-radar(机会雷达)为例,可换成任意自己的生成流程。

目录

wechat-auto-publish/
  prompts/pipeline.md          # 最外层编排提示词
  wechat_auto_publish/         # 包:render + push
  config.example.json
  pyproject.toml

说明

  • 只存草稿,不群发。个人未认证号无 freepublish/submit 权限,发表动作在公众号后台手动点。
  • 如遇报错,如实报告错误信息。

CI / 自动发布

仓库自带 GitHub Actions(.github/workflows/publish.yml),与常见开源 Python 包一致:

  • push 到 main → 编译 sdist + wheel,自动发布到 TestPyPI(官方测试源,验证打包流程不污染正式版);
  • 打 tag v*(如 v0.1.0)→ 编译后发布到正式 PyPI;
  • 也支持在 Actions 页面手动触发(workflow_dispatch),只编译不发布。

免密推送:在 PyPI / TestPyPI 后台把本仓库配置为 Trusted Publisher(OIDC),workflow 里 id-token: write 自动换取临时凭据,不需要任何 PYPI_API_TOKEN。

相关项目

  • opp_radar:机会雷达,按领域提示词自动生成文章内容
  • wechat-formatter:Markdown → 公众号内联样式 HTML(科技风/经典蓝)
  • wechat-publish:公众号草稿箱/群发接口,图片自动转存微信 CDN
  • legal_prompts:法律领域提示词合集
  • gov-site-list:中国政府网站 URL 清单(中央 + 省级 + 部委)
  • gov-monitor:政府网站通知监测工具,自动发现新政策并落库

技术交流

扫码添加微信,交流使用问题、定制与合作:

微信二维码

项目赞助

本项目由以下微信公众号提供赞助,感谢支持:

「程序员白大力」 —— 法律科技 / 自动化内容创作

程序员白大力公众号二维码

「法啊」 —— 法律科普 / 普法内容

法啊公众号二维码

「极速法考」 —— 法考备考 / 法律职业资格考试

极速法考公众号二维码

License

MIT

Release files for wechat-auto-publish 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wechat-auto-publish 1.0.2
File Size Uploaded
wechat_auto_publish-1.0.2.tar.gz 7.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for wechat-auto-publish 1.0.2
File Interpreter ABI Platform
wechat_auto_publish-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 15.2 kB

Release files / wechat_auto_publish-1.0.2.tar.gz

Download URL wechat_auto_publish-1.0.2.tar.gz
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
b1b15564828de0f325eebe82ac66b3d57c2fc8f00c0629538de95c420041e58e
BLAKE2b-256 checksum
How to use checksums
38ae0e252ec82be9b7fe678155a45c6e6bb03ca13fe6b8de1feefd03674767e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 23, 2026.

Transparency log

Release files / wechat_auto_publish-1.0.2-py3-none-any.whl

Download URL wechat_auto_publish-1.0.2-py3-none-any.whl
Size 8.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f339ff1a42fe4e3be3ad70cb73d8637aeb9142109a8cbfcd8de56797b734bc6c
BLAKE2b-256 checksum
How to use checksums
44b59b4b1833e0bf865338eba84fb83e11c9fd3f1eb9d31e52504eecb8d2807b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 23, 2026.

Transparency log

Release history Release notifications | RSS feed

1.0.4

2 release files

1.0.3

2 release files

This release

1.0.2 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page