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" "标题" [摘要]
摘要可省略,微信会自动生成。
命令行:多图文(一条草稿最多 8 篇)
写一个 JSON 清单 manifest.json:
{
"articles": [
{"md": "文章A.md", "cover": "文章A.png", "title": "标题A", "digest": "摘要A(可选,120字内)"},
{"md": "文章B.md", "cover": "文章B.png", "title": "标题B"}
]
}
然后一条命令推送:
wechat-auto-publish draft-multi manifest.json \
--appid 你的AppID --secret 你的AppSecret --author 作者名
- 第一篇为头条封面文章;上限 8 篇;title ≤32 字、digest ≤120 字、author ≤16 字
- 每篇的
.md会先渲染成同款公众号样式 HTML(与draft一致),无需手动渲染 title可省略,默认取 md 文件名;凭据参数与draft完全一致(或走config.json)
编排:生成 + 发布一条龙
给 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.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| wechat_auto_publish-1.0.3.tar.gz | 10.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| wechat_auto_publish-1.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.6 kB
Release files / wechat_auto_publish-1.0.3.tar.gz
| Download URL | wechat_auto_publish-1.0.3.tar.gz |
|---|---|
| Size | 10.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
de4ac4e74bddf37719fb29d61ef3fffc826312cbab75f09ea5cc2571be682ee3
|
|
BLAKE2b-256 checksum How to use checksums |
fb14cc1e005e202a4bd1a2934d718c706e0c3ebd44cf0cfafdcb078ad89f8a2b
|
| 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 24, 2026.
Transparency logRelease files / wechat_auto_publish-1.0.3-py3-none-any.whl
| Download URL | wechat_auto_publish-1.0.3-py3-none-any.whl |
|---|---|
| Size | 9.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dce087b0b3e062fe878fee074668bfc3ee190f9e4a43d89d0c587e274fb8a4c2
|
|
BLAKE2b-256 checksum How to use checksums |
924306edca2046e2c644b5427ac3c6244d25798253501232640528aace656b82
|
| 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 24, 2026.
Transparency log