关于 substack
用于读取 Substack 账户信息和文章,并通过账户已认证的 Web API 发布内容的技能与 Python 命令行工具。它使用会话 Cookie,写入操作需要明确确认。
主要功能
- 01查看登录账户和 publication
- 02列出已发布文章及统计数据
- 03将 Markdown 转为 Substack 格式
- 04写入前预览发布计划
- 05创建草稿或发布文章
适用场景
- 01确认已连接的账户和 publication
- 02查看已发布文章及其统计数据
- 03将文章保存为私人草稿
- 04明确批准后发布文章
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ acedatacloud/ skills --skill substack安装后在 Claude Code 中输入/substack确认已加载。
附带文件scripts/substack.py
详细介绍
substack — 通过自己的 Cookie 在 Substack 上阅读和发布
通过 Substack 使用的同一套内部 Web API 操作用户的真实 Substack 账户(Substack 没有官方公开的写入 API),并使用用户通过 ACE 扩展捕获的登录 Cookie 进行身份验证。无需浏览器,也不依赖第三方库——仅使用 urllib。发布流程与社区库 python-substack 一致:创建草稿 → 预发布 → 发布。
连接器会将 Cookie jar 注入为环境变量:
SUBSTACK_COOKIES— Cookie 的 JSON 数组(substack.sid、substack.lli等)。机密——绝不能回显或打印。 Substack 写入操作仅通过会话 Cookie 进行身份验证(无需 CSRF token 请求头)。
CLI
此技能提供了 scripts/substack.py——仅依赖标准库的独立脚本。
# $SKILL_DIR can point at another skill loaded this turn — anchor on our own
# script, and re-run this at the top of every Bash block (fresh shell each time).
SUB="$SKILL_DIR/scripts/substack.py"; [ -f "$SUB" ] || SUB=$(find /tmp -maxdepth 8 -path '*/skills/*/scripts/substack.py' 2>/dev/null | head -1)
[ -f "$SUB" ] || { echo "substack script not found (SKILL_DIR=$SKILL_DIR)" >&2; exit 1; }
python3 "$SUB" whoami # who is logged in + primary publication
python3 "$SUB" articles --limit 20 # my published posts + stats
请先验证连接
SUB="$SKILL_DIR/scripts/substack.py"; [ -f "$SUB" ] || SUB=$(find /tmp -maxdepth 8 -path '*/skills/*/scripts/substack.py' 2>/dev/null | head -1)
python3 "$SUB" whoami
# → {"user_id": ..., "name": "...", "handle": "...", "publication": "...", "publication_url": "https://<sub>.substack.com"}
如果出现身份验证错误,说明 Cookie 已过期——请让用户前往 https://studio.acedata.cloud/console/connectors 重新连接。不要循环重试。
发布 — 需确认(除非末尾带有 --confirm,否则为试运行)
publish 会写入用户的真实账户。内容使用 Markdown,并转换为 Substack 的 ProseMirror 块:#..######→标题,```→代码块,>→引用块,-/*/1.→列表,---→水平线,其他内容→段落。行内的 粗体、斜体、代码、删除线 和 [链接](url) 会渲染为 Substack 的实际格式;裸露的 https://… URL 会自动转换为链接。
末尾不带 --confirm 时会进行试运行。只有将 --confirm 作为最后一个参数时才会生效。务必先展示试运行结果并取得明确的“是”,然后再重新运行。
SUB="$SKILL_DIR/scripts/substack.py"; [ -f "$SUB" ] || SUB=$(find /tmp -maxdepth 8 -path '*/skills/*/scripts/substack.py' 2>/dev/null | head -1)
# dry-run (shows the plan, writes nothing)
python3 "$SUB" publish --title "Title" --content-file post.md
# private draft (visible only in the user's dashboard)
python3 "$SUB" publish --title "Title" --content-file post.md --draft-only --confirm
# go LIVE on the web (does NOT email subscribers)
python3 "$SUB" publish --title "Title" --content-file post.md --confirm
# go LIVE and email subscribers (use only when the user explicitly asks)
python3 "$SUB" publish --title "Title" --content-file post.md --send-email --confirm
--draft-only会在创建草稿后停止——除非用户要求公开发布,否则默认使用此选项。该选项会返回edit_url,供用户在 Substack 编辑器中查看。- 除非传入
--send-email,否则发布不会向订阅者发送邮件。发送新闻简报邮件不可撤销,且会发送到每位订阅者的收件箱——未经明确请求,绝不要添加--send-email。 --subtitle用于设置文章副标题;--audience可选值为everyone(默认,免费/公开)、only_paid、founding、only_free。
注意事项
- 这是用户的真实 Substack 账户。 发布前务必确认,并将
--draft-only作为安全默认选项。 --send-email会向整个订阅者列表发送邮件,且无法撤销——只有在用户明确要求时才可启用。- Substack 使用 Cloudflare 防护;读取时偶尔出现的 403/429 错误属于暂时情况,CLI 会自动重试读取一次。持续出现 401/403 错误表示 Cookie 确实已过期(需要重新连接);CLI 绝不会重试写入操作。
- 绝不要打印
SUBSTACK_COOKIES——它可授予完整账户访问权限。 - 服务条款:仅使用用户自己捕获的 Cookie 操作其本人账户。
记录输出
成功发布并获取已上线内容的 URL 后,请调用一次内置的
publish_artifact 工具,以便用户在 My Outputs 中跟踪此交付内容:
publish_artifact(kind="article", channel="substack", title="<title>", url="<the REAL returned URL>", status="delivered")
使用实际返回的 URL——绝不要伪造。每个已发布条目仅调用一次,且只能在确认交付后调用;如果发布失败,请跳过(或使用 status="failed")。
参阅 _shared/artifacts.md。