zhihu — search, read & publish on Zhihu
Two authentication layers, two scripts:
| Script | Auth | Capabilities |
|---|---|---|
| scripts/search.py | ZHIHU_DEVELOPER_TOKEN (Bearer) | Search Zhihu, search the web, get hot topics |
| scripts/blog.py | ZHIHU_COOKIES (login cookie) | Read/write own articles & answers |
No browser, no third-party deps — just urllib.
The connector injects credentials as env vars:
ZHIHU_DEVELOPER_TOKEN— Zhihu Developer Platform access secret (Bearer token).
Used for search and hot-list queries. Secret — never echo or print it.
ZHIHU_COOKIES— a JSON array of{name, value, domain, path, ...}cookies.
Used for reading/writing the user's own content. Secret — never echo or print it.
Locate the scripts first (every Bash block)
The connector sets $SKILL_DIR to this skill's directory, so the scripts live at
$SKILL_DIR/scripts/. Do NOT hard-code python3 $SKILL_DIR/scripts/… directly.
If more than one skill was loaded in the same turn, $SKILL_DIR can point at the
other skill and the call fails with No such file or directory (this is the #1
cause of a Zhihu run silently not finishing). Resolve the path defensively at the
top of every Bash block — each Bash call is a fresh shell, so the variable does
not carry over:
# blog.py is unique to this skill, so it anchors zhihu's dir even if $SKILL_DIR is wrong.
ZDIR="$SKILL_DIR"; [ -f "$ZDIR/scripts/blog.py" ] || ZDIR=$(find /tmp -maxdepth 8 -path '*/skills/*/scripts/blog.py' 2>/dev/null | head -1 | sed 's#/scripts/blog.py##')
[ -f "$ZDIR/scripts/blog.py" ] || { echo "zhihu scripts not found (SKILL_DIR=$SKILL_DIR) — is the skill loaded?" >&2; exit 1; }
SEARCH="$ZDIR/scripts/search.py"; BLOG="$ZDIR/scripts/blog.py"
Then use "$SEARCH" / "$BLOG" (always quoted) as shown below.