jianshuo/claude-skills / wjs-publishing-wechat
wjs-publishing-wechat
Unverified当用户想写或发布微信公众号文章时使用——他们给出零散思路、草稿或笔记,请你润色、生成题图和解释图,或准备上传到 mp.weixin.qq.com。触发词:"写一篇微信文章"、"公众号"、"润色"、"题图"、"发公众号"、"/wjs-publishing-wechat"。
| File | Kind | Size |
|---|---|---|
| .gitignore | other | 65 B |
| .publish-manifest.json | config | 13.2 KB |
| LICENSE | other | 1.0 KB |
| README.md | markdown | 4.7 KB |
| SKILL.md | skill md | 14.2 KB |
| STYLE.md | markdown | 10.8 KB |
| prompts/cover-prompt.md | markdown | 20.6 KB |
| prompts/illustration-prompt.md | markdown | 2.8 KB |
| scripts/backfill-permalinks.pyexecutable | script | 9.3 KB |
| scripts/build-recent-articles.pyexecutable | script | 5.5 KB |
| scripts/fetch-comments-by-cookie.shexecutable | script | 12.2 KB |
| scripts/fetch-comments-via-gstack.shexecutable | script | 10.8 KB |
| scripts/fetch-comments.shexecutable | script | 5.4 KB |
| scripts/gen-cover-ai.shexecutable | script | 3.8 KB |
| scripts/gen-illustration.shexecutable | script | 3.0 KB |
| scripts/mass-send.shexecutable | script | 7.2 KB |
| scripts/open-draft-edit.shexecutable | script | 5.3 KB |
| scripts/pangu.py | script | 2.9 KB |
| scripts/update-draft-via-api.pyexecutable | script | 3.9 KB |
| scripts/upload-draft.shexecutable | script | 19.4 KB |
scripts/update-draft-via-api.py
View on GitHub#!/usr/bin/env python3
"""Update an existing WeChat draft in place via the official draft/update API.
Why this exists: md2wechat exposes `create_draft` but not `update_draft` —
even though the underlying library knows the URL. Re-running upload-draft.sh
without this would create a brand-new draft each time, polluting the draft box.
This script reuses the same media_id so WeChat treats it as a new version of
the same draft (built-in version control in the backend).
Network note: api.weixin.qq.com whitelists by IP. On this machine the only
whitelisted egress is via the user's HTTP/HTTPS proxy. httpx picks up
HTTPS_PROXY / HTTP_PROXY env vars automatically; do not strip them.
Usage:
update-draft-via-api.py --draft draft.json --media-id <id>
Exit codes:
0 = updated in place (existing media_id reused)
3 = update rejected (e.g. media_id no longer exists) → caller should fall
back to create_draft
1 = other error (auth, network, malformed input)
"""
import argparse, json, os, sys
import urllib.request, urllib.error
import urllib.parse
API_TOKEN = "https://api.weixin.qq.com/cgi-bin/token"
API_UPDATE = "https://api.weixin.qq.com/cgi-bin/draft/update"
# Errcodes that mean "this draft is gone, please create a fresh one".
GONE_ERRCODES = {
40007, # invalid media_id (stale; was deleted/replaced)
46003, # media data invalid
47001, # data format error
}
def http_post_json(url: str, body: dict, timeout: float = 30.0) -> dict:
data = json.dumps(body, ensure_ascii=False).encode("utf-8")
req = urllib.request.Request(
url,
data=data,
headers={"Content-Type": "application/json; charset=utf-8"},
method="POST",
)
# urllib honors http_proxy / https_proxy env vars via ProxyHandler default.
with urllib.request.urlopen(req, timeout=timeout) as r:
return json.loads(r.read().decode("utf-8"))
def http_get_json(url: str, params: dict, timeout: float = 30.0) -> dict:
q = urllib.parse.urlencode(params)
with urllib.request.urlopen(f"{url}?{q}", timeout=timeout) as r:
return json.loads(r.read().decode("utf-8"))
def get_access_token() -> str:
appid = os.environ.get("WECHAT_APPID")
secret = os.environ.get("WECHAT_SECRET")
if not appid or not secret:
sys.exit("WECHAT_APPID / WECHAT_SECRET must be set in env")
r = http_get_json(API_TOKEN, {
"grant_type": "client_credential",
"appid": appid,
"secret": secret,
})
if "access_token" not in r:
# 40164 = IP not whitelisted; common cause: proxy was stripped.
sys.exit(f"access_token fetch failed: {r}")
return r["access_token"]
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--draft", required=True, help="path to draft.json (md2wechat format: {articles:[{...}]})")
ap.add_argument("--media-id", required=True, help="existing draft media_id to update in place")
args = ap.parse_args()
draft = json.load(open(args.draft))
articles = draft.get("articles") or []
if not articles:
sys.exit("draft.json has no articles[]")
if len(articles) > 1:
sys.exit("draft has multiple articles — update API takes one at a time; not supported here")
token = get_access_token()
body = {
"media_id": args.media_id,
"index": 0,
"articles": articles[0],
}
url = f"{API_UPDATE}?access_token={token}"
resp = http_post_json(url, body)
errcode = resp.get("errcode", 0)
if errcode == 0:
print(json.dumps({"ok": True, "media_id": args.media_id}, ensure_ascii=False))
return 0
if errcode in GONE_ERRCODES:
sys.stderr.write(f"draft no longer exists (errcode={errcode} {resp.get('errmsg')}); caller should create new\n")
return 3
# Other errors (e.g. 45004 description too long): bubble up
sys.stderr.write(f"draft/update failed: {resp}\n")
return 1
if __name__ == "__main__":
sys.exit(main())
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |