scrape-zyte-login
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAPI keys must never appear in the transcript. Do not echo, read, or write key values directly.
SHUB_APIKEYZYTE_API_KEY.env.envAPI密钥绝对不能出现在对话记录中。请勿直接回显、读取或写入密钥值。
SHUB_APIKEYZYTE_API_KEY.env.env1. Check credentials
1. 检查凭证
Report whether each key is set in the environment or stored in (do not export anything):
.envbash
{ [ -n "$ZYTE_API_KEY" ] || grep -q '^ZYTE_API_KEY=' .env 2>/dev/null; } && echo "ZYTE_API_KEY: present" || echo "ZYTE_API_KEY: missing"
{ [ -n "$SHUB_APIKEY" ] || grep -q '^SHUB_APIKEY=' .env 2>/dev/null; } && echo "SHUB_APIKEY: present" || echo "SHUB_APIKEY: missing"If both are present, proceed to step 3.
报告每个密钥是否已在环境中设置或存储在 文件中(请勿导出任何内容):
.envbash
{ [ -n "$ZYTE_API_KEY" ] || grep -q '^ZYTE_API_KEY=' .env 2>/dev/null; } && echo "ZYTE_API_KEY: present" || echo "ZYTE_API_KEY: missing"
{ [ -n "$SHUB_APIKEY" ] || grep -q '^SHUB_APIKEY=' .env 2>/dev/null; } && echo "SHUB_APIKEY: present" || echo "SHUB_APIKEY: missing"如果两个密钥都已存在,直接进入步骤3。
2. Run OAuth setup flow
2. 运行OAuth设置流程
Tell the user:
I'm starting the Zyte OAuth setup flow in your browser. Please complete login/consent there.
Run the OAuth flow script:
bash
uv run ${CLAUDE_SKILL_DIR}/scripts/oauth.py --productionThe script stores directly in (the value is never printed) and saves a projects-and-keys file. Its output includes lines like and . Scan the output and identify the path for the projects-and-keys file.
SHUB_APIKEY.envSaved data to /path/to/fileSaved SHUB_APIKEY to .envMake sure stays out of version control:
.envbash
grep -qxF '.env' .gitignore 2>/dev/null || echo '.env' >> .gitignore告知用户:
我将在你的浏览器中启动Zyte OAuth设置流程,请在那里完成登录/授权操作。
运行OAuth流程脚本:
bash
uv run ${CLAUDE_SKILL_DIR}/scripts/oauth.py --production该脚本会将 直接存储在 文件中(密钥值绝不会被打印),并保存一个项目与密钥文件。其输出包含类似 和 的行。扫描输出内容,找到项目与密钥文件的路径。
SHUB_APIKEY.envSaved data to /path/to/fileSaved SHUB_APIKEY to .env确保 文件不纳入版本控制:
.envbash
grep -qxF '.env' .gitignore 2>/dev/null || echo '.env' >> .gitignore3. Let user pick project and Zyte API key
3. 让用户选择项目和Zyte API密钥
From the projects-and-keys file found in step 2, list to the user:
- All available projects: and
project idproject name - All available Zyte API keys: (never show key values)
apikey name
Ask the user to choose exactly one project and one API key by name.
After the user picks an API key, resolve its download URL from the same file, download it, and store it in under , replacing any existing entry. The value is never printed to the terminal and is not exported to the shell ( is read from ).
.envZYTE_API_KEYSHUB_APIKEY.envThe wrapper script prints the HTTP status code on its first line and the response body on the rest. The command below guards against writing a failed response (e.g. an auth error body) into as if it were a key: it saves the key only when the status is , and otherwise prints the server response so you can report the failure to the user (the key value is never printed):
.env200bash
OUT="$(uv run ${CLAUDE_SKILL_DIR}/../scrape-scrapy-cloud/scripts/scrapy_cloud_api.py GET $URL)"
if [ "$(printf '%s\n' "$OUT" | head -n1)" = "200" ]; then
{ grep -v '^ZYTE_API_KEY=' .env 2>/dev/null; printf 'ZYTE_API_KEY=%s\n' "$(printf '%s\n' "$OUT" | tail -n +2)"; } > .env.tmp && mv .env.tmp .env
echo "ZYTE_API_KEY stored in .env"
else
echo "Failed to download Zyte API key; .env left unchanged. Server response:"
printf '%s\n' "$OUT"
fiIf it reports a failure, do not proceed; the most common cause is a missing or unresolved (needs , which reads it from ).
SHUB_APIKEYshub>=2.18.1.envCleanup the projects-and-keys file after reading:
bash
rm /path/to/projects-and-keys.json从步骤2中找到的项目与密钥文件里,向用户列出:
- 所有可用项目:和
project idproject name - 所有可用Zyte API密钥:(绝不能显示密钥值)
apikey name
请用户通过名称选择恰好一个项目和一个API密钥。
用户选择API密钥后,从同一文件中解析其下载URL,下载密钥并将其存储在 文件的 字段下,替换任何现有条目。密钥值绝不会打印到终端,也不会导出到Shell环境( 会从 文件读取)。
.envZYTE_API_KEYSHUB_APIKEY.env包装脚本会在第一行打印HTTP状态码,其余行打印响应体。下面的命令可防止将失败响应(如认证错误内容)当作密钥写入 文件:仅当状态码为 时才保存密钥,否则打印服务器响应以便你向用户报告失败(密钥值绝不会被打印):
.env200bash
OUT="$(uv run ${CLAUDE_SKILL_DIR}/../scrape-scrapy-cloud/scripts/scrapy_cloud_api.py GET $URL)"
if [ "$(printf '%s\n' "$OUT" | head -n1)" = "200" ]; then
{ grep -v '^ZYTE_API_KEY=' .env 2>/dev/null; printf 'ZYTE_API_KEY=%s\n' "$(printf '%s\n' "$OUT" | tail -n +2)"; } > .env.tmp && mv .env.tmp .env
echo "ZYTE_API_KEY stored in .env"
else
echo "Failed to download Zyte API key; .env left unchanged. Server response:"
printf '%s\n' "$OUT"
fi如果报告失败,请不要继续操作;最常见的原因是 缺失或未解析(需要 ,该版本会从 文件读取密钥)。
SHUB_APIKEYshub>=2.18.1.env读取完成后清理项目与密钥文件:
bash
rm /path/to/projects-and-keys.json4. Save selected project ID
4. 保存选中的项目ID
If the user selected a project ID in step 3, save it:
bash
mkdir -p .scrape/.zyte
echo "PROJECT_ID" > .scrape/.zyte/project-idIf no project was selected, skip. Tell the user: "Zyte credentials are active."
Return to the caller:
Zyte setup complete:
ZYTE_API_KEY: present
SHUB_APIKEY: present
Project ID: 12345 (or not saved)如果用户在步骤3中选择了项目ID,保存该ID:
bash
mkdir -p .scrape/.zyte
echo "PROJECT_ID" > .scrape/.zyte/project-id如果未选择项目,请跳过此步骤。告知用户:"Zyte凭证已激活。"
向调用方返回:
Zyte setup complete:
ZYTE_API_KEY: present
SHUB_APIKEY: present
Project ID: 12345 (or not saved)