goofish-cli 0.5.2__tar.gz → 0.6.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/.claude-plugin/marketplace.json +1 -1
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/CHANGELOG.md +15 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/PKG-INFO +43 -18
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/README.md +42 -17
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/pyproject.toml +1 -1
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/cli.py +2 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/commands/item/get.py +10 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/commands/item/view.py +71 -15
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/core/browser.py +20 -5
- goofish_cli-0.6.0/src/goofish_cli/core/item_page.py +141 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/core/local_state.py +7 -2
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/core/qr_login.py +68 -32
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/core/refresh.py +1 -1
- goofish_cli-0.6.0/src/goofish_cli/core/sandbox_browser.py +135 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/core/session.py +46 -4
- goofish_cli-0.6.0/src/goofish_cli/sandbox/__init__.py +1 -0
- goofish_cli-0.6.0/src/goofish_cli/sandbox/assets/Dockerfile +13 -0
- goofish_cli-0.6.0/src/goofish_cli/sandbox/assets/entrypoint.sh +51 -0
- goofish_cli-0.6.0/src/goofish_cli/sandbox/cli.py +323 -0
- goofish_cli-0.6.0/src/goofish_cli/sandbox/interactive.py +53 -0
- goofish_cli-0.6.0/src/goofish_cli/sandbox/runtime.py +34 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/.gitignore +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/LICENSE +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/NOTICE +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/examples/README.md +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/skills/goofish-overview/SKILL.md +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/skills/goofish-overview/references/accounts.md +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/skills/goofish-overview/references/mcp-tools-index.md +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/skills/goofish-overview/references/xianyu-concepts.md +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/skills/goofish-publish-item/SKILL.md +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/skills/goofish-publish-item/references/category-selection.md +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/skills/goofish-publish-item/references/common-pitfalls.md +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/skills/goofish-publish-item/references/image-checklist.md +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/skills/goofish-publish-item/references/title-formula.md +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/skills/goofish-reply-buyer/SKILL.md +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/skills/goofish-reply-buyer/references/bargain-ladder.md +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/skills/goofish-reply-buyer/references/intent-classification.md +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/skills/goofish-reply-buyer/references/tone-guide.md +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/skills/goofish-risk-guard/SKILL.md +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/skills/goofish-risk-guard/references/external-contact-keywords.md +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/skills/goofish-risk-guard/references/forbidden-words.md +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/skills/goofish-risk-guard/references/publish-red-lines.md +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/skills/goofish-risk-guard/references/x5sec-recovery.md +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/skills/goofish-shop-diagnosis/SKILL.md +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/skills/goofish-shop-diagnosis/references/diagnosis-workflow.md +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/skills/goofish-shop-diagnosis/references/rank-factors.md +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/skills/goofish-shop-diagnosis/references/traffic-drop-causes.md +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/__init__.py +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/commands/__init__.py +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/commands/auth/__init__.py +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/commands/auth/login.py +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/commands/auth/reset_guard.py +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/commands/auth/status.py +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/commands/category/__init__.py +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/commands/category/recommend.py +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/commands/item/__init__.py +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/commands/item/delete.py +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/commands/item/list.py +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/commands/item/publish.py +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/commands/location/__init__.py +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/commands/location/default.py +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/commands/media/__init__.py +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/commands/media/upload.py +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/commands/message/__init__.py +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/commands/message/history.py +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/commands/message/list_chats.py +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/commands/message/send.py +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/commands/message/watch.py +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/commands/search/__init__.py +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/commands/search/search.py +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/commands/skills/__init__.py +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/commands/skills/install.py +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/core/__init__.py +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/core/browser_cookie.py +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/core/cookie_types.py +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/core/crypto.py +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/core/errors.py +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/core/guard.py +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/core/item_data.py +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/core/limiter.py +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/core/message_history.py +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/core/mtop.py +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/core/output.py +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/core/registry.py +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/core/search_data.py +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/core/sign.py +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/core/strategy.py +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/core/token.py +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/core/write_operation.py +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/core/ws.py +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/mcp_server.py +0 -0
- {goofish_cli-0.5.2 → goofish_cli-0.6.0}/src/goofish_cli/static/goofish_js_version_2.js +0 -0
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"name": "goofish-cli-skills",
|
|
4
4
|
"displayName": "goofish-cli Skills",
|
|
5
5
|
"description": "闲鱼(goofish.com)自动化运营的 Claude Skills 套件。配合 goofish-cli MCP server 使用,让 Agent 在发布商品 / 回复买家 / 风控预检 / 店铺诊断这些场景里上手即会。",
|
|
6
|
-
"version": "0.
|
|
6
|
+
"version": "0.6.0",
|
|
7
7
|
"author": {
|
|
8
8
|
"name": "fancy",
|
|
9
9
|
"url": "https://github.com/fancyboi999"
|
|
@@ -4,6 +4,21 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/).
|
|
6
6
|
|
|
7
|
+
## [0.6.0](https://github.com/fancyboi999/goofish-cli/compare/v0.5.3...v0.6.0) (2026-10-19)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
* 支持 Docker 独立桌面沙箱模式 ([#45](https://github.com/fancyboi999/goofish-cli/issues/45)) ([cce6d69](https://github.com/fancyboi999/goofish-cli/commit/cce6d696fedf535a9e6239f340fa1dc033303d25))
|
|
13
|
+
|
|
14
|
+
## [0.5.3](https://github.com/fancyboi999/goofish-cli/compare/v0.5.2...v0.5.3) (2026-10-12)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Documentation
|
|
18
|
+
|
|
19
|
+
* **readme:** embed native GitHub video player with sound ([101211b](https://github.com/fancyboi999/goofish-cli/commit/101211b6889455307ce9dc7e1e5f3c1db7c67508))
|
|
20
|
+
* **readme:** embed native GitHub video player with sound ([a7bdfbd](https://github.com/fancyboi999/goofish-cli/commit/a7bdfbd0dfd8637f95e25e81edbf72e1c0762451))
|
|
21
|
+
|
|
7
22
|
## [0.5.2](https://github.com/fancyboi999/goofish-cli/compare/v0.5.1...v0.5.2) (2026-10-10)
|
|
8
23
|
|
|
9
24
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: goofish-cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.6.0
|
|
4
4
|
Summary: 闲鱼 CLI — 支持 MCP,未来支持 Claude Skills。为 AI Agent 提供闲鱼自动化基础能力。
|
|
5
5
|
Project-URL: Homepage, https://github.com/fancyboi999/goofish-cli
|
|
6
6
|
Project-URL: Repository, https://github.com/fancyboi999/goofish-cli
|
|
@@ -56,22 +56,12 @@ Description-Content-Type: text/markdown
|
|
|
56
56
|
|
|
57
57
|
</div>
|
|
58
58
|
|
|
59
|
+
https://github.com/user-attachments/assets/ae20ae2f-ccdf-4d3e-a947-69182d4c4eff
|
|
60
|
+
|
|
59
61
|
<p align="center">
|
|
60
|
-
<a href="media/goofish-cli-promo.mp4">
|
|
61
|
-
<img src="media/goofish-cli-promo.gif" alt="goofish-cli 演示" width="760">
|
|
62
|
-
</a>
|
|
63
|
-
<br>
|
|
64
|
-
<em>▶️ 点击查看带终端音效 + 配乐的高清 MP4(46s)</em>
|
|
62
|
+
<em>▶️ 播放不了?<a href="media/goofish-cli-promo.mp4">点这里下载高清 MP4(1:32)</a></em>
|
|
65
63
|
</p>
|
|
66
64
|
|
|
67
|
-
<!--
|
|
68
|
-
想在 README 里内嵌「带声音的播放器」?GitHub 上唯一的办法:
|
|
69
|
-
1. 打开本仓库任意 issue / PR 评论框(或 Releases 编辑页)
|
|
70
|
-
2. 把 media/goofish-cli-promo.mp4 拖进去,等它生成 https://github.com/user-attachments/assets/xxxx 链接
|
|
71
|
-
3. 把那串链接单独一行粘进这里,GitHub 会自动渲染成带声音的播放器
|
|
72
|
-
(提交进仓库的 mp4 用 <video> 标签会被 GitHub 过滤,不渲染)
|
|
73
|
-
-->
|
|
74
|
-
|
|
75
65
|
`goofish-cli` 把闲鱼(Xianyu/Goofish)的核心运营能力抽成一套结构化命令,
|
|
76
66
|
**同一份定义**同时输出给四种消费者:
|
|
77
67
|
|
|
@@ -133,6 +123,39 @@ goofish message watch # 实时接收消息
|
|
|
133
123
|
goofish message send <cid> <toid> --text "在的" # 发消息
|
|
134
124
|
```
|
|
135
125
|
|
|
126
|
+
### 不占用桌面的沙箱模式
|
|
127
|
+
|
|
128
|
+
需要运行中的本机 Docker Desktop / Docker Engine。安装支持沙箱的版本后,先在终端执行:
|
|
129
|
+
|
|
130
|
+
```sh
|
|
131
|
+
goofish sandbox --help
|
|
132
|
+
goofish sandbox start
|
|
133
|
+
# 手动打开输出的观察链接,默认 http://127.0.0.1:16080/vnc.html?autoconnect=1&resize=scale
|
|
134
|
+
goofish sandbox login # 在虚拟桌面里扫码并确认
|
|
135
|
+
|
|
136
|
+
goofish sandbox run auth status --format json
|
|
137
|
+
goofish sandbox run search items '机械键盘' --limit 3
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
让 AI 客户端也使用沙箱时,将原有 `goofish` MCP 配置替换为:
|
|
141
|
+
|
|
142
|
+
```json
|
|
143
|
+
{
|
|
144
|
+
"mcpServers": {
|
|
145
|
+
"goofish": {
|
|
146
|
+
"command": "goofish",
|
|
147
|
+
"args": ["sandbox", "mcp"]
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
客户端必须能找到 `goofish` 和 `docker`;桌面客户端找不到命令时,将 `command` 改为 `command -v goofish` 输出的绝对路径,并检查客户端 PATH 中是否有 Docker。Codex 使用 TOML,见 [MCP 客户端配置](docs/mcp-setup.md#独立桌面模式)。不要同时保留原来的本机 Goofish server;直接运行 `uvx goofish-cli` 仍使用本机模式。
|
|
154
|
+
|
|
155
|
+
首次启动会下载并构建镜像。Chromium 在容器虚拟桌面里常驻,登录态保存在独立卷;命令不会自动打开宿主机浏览器。平台要求验证时,执行 `goofish sandbox browse --item-id <商品ID>`,在观察页面人工完成。升级后用 `stop`、`start --rebuild` 更新镜像,状态卷保留。
|
|
156
|
+
|
|
157
|
+
如果 `sandbox --help` 不识别命令,当前安装的发行版尚未包含沙箱功能。源码安装、完整的登录/恢复步骤和限制见[沙箱指南](docs/sandbox.md)。
|
|
158
|
+
|
|
136
159
|
---
|
|
137
160
|
|
|
138
161
|
## 🧩 Claude Skills(v0.3 新增)
|
|
@@ -180,7 +203,7 @@ OpenClaw `2026.6.1` 及以上可把本仓库作为 compatible bundle 加载。
|
|
|
180
203
|
openclaw plugins install clawhub:openclaw-goofish
|
|
181
204
|
|
|
182
205
|
# 登录态由用户在终端初始化,不交给 Agent 覆盖
|
|
183
|
-
uvx --from goofish-cli==0.
|
|
206
|
+
uvx --from goofish-cli==0.6.0 goofish auth login --qr
|
|
184
207
|
|
|
185
208
|
openclaw plugins inspect goofish --json
|
|
186
209
|
openclaw gateway restart
|
|
@@ -325,7 +348,9 @@ goofish item publish "男士毛呢大衣 驼色长款" \
|
|
|
325
348
|
|
|
326
349
|
## 🔌 接入 Claude Code(MCP)
|
|
327
350
|
|
|
328
|
-
|
|
351
|
+
以下为本机模式;需要隔离桌面时,使用上面的沙箱 MCP 配置,客户端位置见 [MCP 接入指南](docs/mcp-setup.md)。
|
|
352
|
+
|
|
353
|
+
在项目根目录 `.mcp.json` 配置:
|
|
329
354
|
|
|
330
355
|
```json
|
|
331
356
|
{
|
|
@@ -338,7 +363,7 @@ goofish item publish "男士毛呢大衣 驼色长款" \
|
|
|
338
363
|
}
|
|
339
364
|
```
|
|
340
365
|
|
|
341
|
-
Claude 会自动把全部命令看成 tool:`
|
|
366
|
+
Claude 会自动把全部命令看成 tool:`mcp__goofish__item_get` / `mcp__goofish__item_publish` / `mcp__goofish__message_watch`... 你在对话里直接说"帮我看下 itemId=xxx 的详情",Claude 就会调用。
|
|
342
367
|
|
|
343
368
|
---
|
|
344
369
|
|
|
@@ -353,7 +378,7 @@ Claude 会自动把全部命令看成 tool:`goofish_item_get` / `goofish_item_
|
|
|
353
378
|
| WebSocket 自动重连 | 断线自退避重连,长跑无感知 |
|
|
354
379
|
| 已读回执 / typing / 新消息通知分类 | `/s/sync` 元事件结构化为三类 JSONL |
|
|
355
380
|
| 全局限流 + 风控熔断 | 账号业务预算 + RGV587 自动熔断 |
|
|
356
|
-
|
|
|
381
|
+
| 回归验证 | `pytest` + `ruff check src tests` |
|
|
357
382
|
| 包分发 | `pip install goofish-cli` / `uvx goofish-cli` |
|
|
358
383
|
|
|
359
384
|
---
|
|
@@ -15,22 +15,12 @@
|
|
|
15
15
|
|
|
16
16
|
</div>
|
|
17
17
|
|
|
18
|
+
https://github.com/user-attachments/assets/ae20ae2f-ccdf-4d3e-a947-69182d4c4eff
|
|
19
|
+
|
|
18
20
|
<p align="center">
|
|
19
|
-
<a href="media/goofish-cli-promo.mp4">
|
|
20
|
-
<img src="media/goofish-cli-promo.gif" alt="goofish-cli 演示" width="760">
|
|
21
|
-
</a>
|
|
22
|
-
<br>
|
|
23
|
-
<em>▶️ 点击查看带终端音效 + 配乐的高清 MP4(46s)</em>
|
|
21
|
+
<em>▶️ 播放不了?<a href="media/goofish-cli-promo.mp4">点这里下载高清 MP4(1:32)</a></em>
|
|
24
22
|
</p>
|
|
25
23
|
|
|
26
|
-
<!--
|
|
27
|
-
想在 README 里内嵌「带声音的播放器」?GitHub 上唯一的办法:
|
|
28
|
-
1. 打开本仓库任意 issue / PR 评论框(或 Releases 编辑页)
|
|
29
|
-
2. 把 media/goofish-cli-promo.mp4 拖进去,等它生成 https://github.com/user-attachments/assets/xxxx 链接
|
|
30
|
-
3. 把那串链接单独一行粘进这里,GitHub 会自动渲染成带声音的播放器
|
|
31
|
-
(提交进仓库的 mp4 用 <video> 标签会被 GitHub 过滤,不渲染)
|
|
32
|
-
-->
|
|
33
|
-
|
|
34
24
|
`goofish-cli` 把闲鱼(Xianyu/Goofish)的核心运营能力抽成一套结构化命令,
|
|
35
25
|
**同一份定义**同时输出给四种消费者:
|
|
36
26
|
|
|
@@ -92,6 +82,39 @@ goofish message watch # 实时接收消息
|
|
|
92
82
|
goofish message send <cid> <toid> --text "在的" # 发消息
|
|
93
83
|
```
|
|
94
84
|
|
|
85
|
+
### 不占用桌面的沙箱模式
|
|
86
|
+
|
|
87
|
+
需要运行中的本机 Docker Desktop / Docker Engine。安装支持沙箱的版本后,先在终端执行:
|
|
88
|
+
|
|
89
|
+
```sh
|
|
90
|
+
goofish sandbox --help
|
|
91
|
+
goofish sandbox start
|
|
92
|
+
# 手动打开输出的观察链接,默认 http://127.0.0.1:16080/vnc.html?autoconnect=1&resize=scale
|
|
93
|
+
goofish sandbox login # 在虚拟桌面里扫码并确认
|
|
94
|
+
|
|
95
|
+
goofish sandbox run auth status --format json
|
|
96
|
+
goofish sandbox run search items '机械键盘' --limit 3
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
让 AI 客户端也使用沙箱时,将原有 `goofish` MCP 配置替换为:
|
|
100
|
+
|
|
101
|
+
```json
|
|
102
|
+
{
|
|
103
|
+
"mcpServers": {
|
|
104
|
+
"goofish": {
|
|
105
|
+
"command": "goofish",
|
|
106
|
+
"args": ["sandbox", "mcp"]
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
客户端必须能找到 `goofish` 和 `docker`;桌面客户端找不到命令时,将 `command` 改为 `command -v goofish` 输出的绝对路径,并检查客户端 PATH 中是否有 Docker。Codex 使用 TOML,见 [MCP 客户端配置](docs/mcp-setup.md#独立桌面模式)。不要同时保留原来的本机 Goofish server;直接运行 `uvx goofish-cli` 仍使用本机模式。
|
|
113
|
+
|
|
114
|
+
首次启动会下载并构建镜像。Chromium 在容器虚拟桌面里常驻,登录态保存在独立卷;命令不会自动打开宿主机浏览器。平台要求验证时,执行 `goofish sandbox browse --item-id <商品ID>`,在观察页面人工完成。升级后用 `stop`、`start --rebuild` 更新镜像,状态卷保留。
|
|
115
|
+
|
|
116
|
+
如果 `sandbox --help` 不识别命令,当前安装的发行版尚未包含沙箱功能。源码安装、完整的登录/恢复步骤和限制见[沙箱指南](docs/sandbox.md)。
|
|
117
|
+
|
|
95
118
|
---
|
|
96
119
|
|
|
97
120
|
## 🧩 Claude Skills(v0.3 新增)
|
|
@@ -139,7 +162,7 @@ OpenClaw `2026.6.1` 及以上可把本仓库作为 compatible bundle 加载。
|
|
|
139
162
|
openclaw plugins install clawhub:openclaw-goofish
|
|
140
163
|
|
|
141
164
|
# 登录态由用户在终端初始化,不交给 Agent 覆盖
|
|
142
|
-
uvx --from goofish-cli==0.
|
|
165
|
+
uvx --from goofish-cli==0.6.0 goofish auth login --qr
|
|
143
166
|
|
|
144
167
|
openclaw plugins inspect goofish --json
|
|
145
168
|
openclaw gateway restart
|
|
@@ -284,7 +307,9 @@ goofish item publish "男士毛呢大衣 驼色长款" \
|
|
|
284
307
|
|
|
285
308
|
## 🔌 接入 Claude Code(MCP)
|
|
286
309
|
|
|
287
|
-
|
|
310
|
+
以下为本机模式;需要隔离桌面时,使用上面的沙箱 MCP 配置,客户端位置见 [MCP 接入指南](docs/mcp-setup.md)。
|
|
311
|
+
|
|
312
|
+
在项目根目录 `.mcp.json` 配置:
|
|
288
313
|
|
|
289
314
|
```json
|
|
290
315
|
{
|
|
@@ -297,7 +322,7 @@ goofish item publish "男士毛呢大衣 驼色长款" \
|
|
|
297
322
|
}
|
|
298
323
|
```
|
|
299
324
|
|
|
300
|
-
Claude 会自动把全部命令看成 tool:`
|
|
325
|
+
Claude 会自动把全部命令看成 tool:`mcp__goofish__item_get` / `mcp__goofish__item_publish` / `mcp__goofish__message_watch`... 你在对话里直接说"帮我看下 itemId=xxx 的详情",Claude 就会调用。
|
|
301
326
|
|
|
302
327
|
---
|
|
303
328
|
|
|
@@ -312,7 +337,7 @@ Claude 会自动把全部命令看成 tool:`goofish_item_get` / `goofish_item_
|
|
|
312
337
|
| WebSocket 自动重连 | 断线自退避重连,长跑无感知 |
|
|
313
338
|
| 已读回执 / typing / 新消息通知分类 | `/s/sync` 元事件结构化为三类 JSONL |
|
|
314
339
|
| 全局限流 + 风控熔断 | 账号业务预算 + RGV587 自动熔断 |
|
|
315
|
-
|
|
|
340
|
+
| 回归验证 | `pytest` + `ruff check src tests` |
|
|
316
341
|
| 包分发 | `pip install goofish-cli` / `uvx goofish-cli` |
|
|
317
342
|
|
|
318
343
|
---
|
|
@@ -12,6 +12,7 @@ from goofish_cli.core import GoofishError, iter_commands
|
|
|
12
12
|
from goofish_cli.core.errors import PartialResultError
|
|
13
13
|
from goofish_cli.core.output import Format, render
|
|
14
14
|
from goofish_cli.core.registry import Command, discover
|
|
15
|
+
from goofish_cli.sandbox.cli import app as sandbox_app
|
|
15
16
|
|
|
16
17
|
app = typer.Typer(
|
|
17
18
|
name="goofish",
|
|
@@ -19,6 +20,7 @@ app = typer.Typer(
|
|
|
19
20
|
no_args_is_help=True,
|
|
20
21
|
add_completion=False,
|
|
21
22
|
)
|
|
23
|
+
app.add_typer(sandbox_app, name="sandbox")
|
|
22
24
|
|
|
23
25
|
|
|
24
26
|
def _format_option() -> typer.Option:
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
"""item get — 查询商品详情。接口 mtop.taobao.idle.pc.detail v1.0(只读)"""
|
|
2
2
|
|
|
3
|
+
import asyncio
|
|
4
|
+
import os
|
|
3
5
|
from typing import Any
|
|
4
6
|
|
|
5
7
|
from goofish_cli.core import Session, Strategy, command
|
|
6
8
|
from goofish_cli.core.item_data import normalize_item
|
|
9
|
+
from goofish_cli.core.item_page import fetch_item_page
|
|
7
10
|
from goofish_cli.core.mtop import call
|
|
8
11
|
|
|
9
12
|
|
|
@@ -15,6 +18,13 @@ from goofish_cli.core.mtop import call
|
|
|
15
18
|
columns=["item_id", "title", "price", "seller_nick", "status"],
|
|
16
19
|
)
|
|
17
20
|
def get(item_id: str) -> dict[str, Any]:
|
|
21
|
+
if os.environ.get("GOOFISH_DESKTOP_SANDBOX") == "1":
|
|
22
|
+
if not str(item_id).isdigit():
|
|
23
|
+
from goofish_cli.core.errors import GoofishError
|
|
24
|
+
|
|
25
|
+
raise GoofishError("商品 ID 必须为数字")
|
|
26
|
+
raw = asyncio.run(fetch_item_page(str(item_id)))
|
|
27
|
+
return normalize_item(raw, str(item_id))
|
|
18
28
|
session = Session.load()
|
|
19
29
|
raw = call(
|
|
20
30
|
session,
|
|
@@ -1,26 +1,22 @@
|
|
|
1
|
-
"""item view —
|
|
1
|
+
"""item view — 浏览器商品详情。沙箱读取页面自身的响应并校验身份。
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
好处:
|
|
6
|
-
|
|
7
|
-
1. **字段完整**:直接按 OpenCLI 的提取器从 `data.itemDO / data.sellerDO / itemLabelExtList`
|
|
8
|
-
抽 20+ 字段(description / want_count / browse_count / 成色 / 品牌 / image_urls /
|
|
9
|
-
seller_score / reply_ratio_24h 等)。
|
|
10
|
-
2. **抗风控兜底**:CLI 直签偶尔遇到 x5sec / h5_token 失效,浏览器路径作为备份链路。
|
|
11
|
-
|
|
12
|
-
保留 `item get`(快且不需要 Chrome),两条路并存。用户根据场景选。
|
|
3
|
+
本机保留原有页面 SDK 调用;沙箱 item get 与 view 共用常驻浏览器路径。
|
|
4
|
+
平台要求验证时明确报错并保留沙箱页面,由用户亲自处理。
|
|
13
5
|
"""
|
|
6
|
+
|
|
14
7
|
from __future__ import annotations
|
|
15
8
|
|
|
16
9
|
import asyncio
|
|
17
10
|
import json
|
|
11
|
+
import os
|
|
18
12
|
import re
|
|
19
13
|
from typing import Any
|
|
20
14
|
|
|
21
15
|
from goofish_cli.core import Strategy, command
|
|
22
16
|
from goofish_cli.core.browser import goofish_page
|
|
23
17
|
from goofish_cli.core.errors import AuthRequiredError, GoofishError
|
|
18
|
+
from goofish_cli.core.item_data import normalize_item
|
|
19
|
+
from goofish_cli.core.item_page import read_item_page
|
|
24
20
|
|
|
25
21
|
|
|
26
22
|
def _normalize_item_id(value: Any) -> str:
|
|
@@ -34,6 +30,47 @@ def _build_item_url(item_id: str) -> str:
|
|
|
34
30
|
return f"https://www.goofish.com/item?id={item_id}"
|
|
35
31
|
|
|
36
32
|
|
|
33
|
+
def _view_result(raw: dict[str, Any], item_id: str) -> dict[str, Any]:
|
|
34
|
+
base = normalize_item(raw, item_id)
|
|
35
|
+
data = raw["data"]
|
|
36
|
+
item, seller = data["itemDO"], data.get("sellerDO") or {}
|
|
37
|
+
|
|
38
|
+
def clean(value):
|
|
39
|
+
return re.sub(r"\s+", " ", str(value if value is not None else "")).strip()
|
|
40
|
+
|
|
41
|
+
images = [
|
|
42
|
+
image["url"]
|
|
43
|
+
for image in item.get("imageInfos") or []
|
|
44
|
+
if isinstance(image, dict) and image.get("url")
|
|
45
|
+
]
|
|
46
|
+
result = {key: value for key, value in base.items() if key not in {"raw", "seller_nick"}}
|
|
47
|
+
result.update(
|
|
48
|
+
title=clean(base["title"]),
|
|
49
|
+
description=clean(base["description"]),
|
|
50
|
+
price="¥" + clean(base["price"]) if base["price"] is not None else None,
|
|
51
|
+
original_price=clean(base["original_price"]),
|
|
52
|
+
seller_name=clean(base["seller_nick"]),
|
|
53
|
+
seller_id=clean(base["seller_id"]),
|
|
54
|
+
status=clean(base["status"]),
|
|
55
|
+
location=clean(base["location"]),
|
|
56
|
+
condition=clean(base["condition"]),
|
|
57
|
+
brand=clean(base["brand"]),
|
|
58
|
+
category=clean(base["category"]),
|
|
59
|
+
want_count=clean(item.get("wantCnt")),
|
|
60
|
+
collect_count=clean(item.get("collectCnt")),
|
|
61
|
+
browse_count=clean(item.get("browseCnt")),
|
|
62
|
+
seller_score=clean(seller.get("xianyuSummary")),
|
|
63
|
+
reply_ratio_24h=clean(seller.get("replyRatio24h")),
|
|
64
|
+
reply_interval=clean(seller.get("replyInterval")),
|
|
65
|
+
seller_url="https://www.goofish.com/personal?userId=" + clean(base["seller_id"])
|
|
66
|
+
if base["seller_id"] is not None
|
|
67
|
+
else "",
|
|
68
|
+
image_count=str(len(images)),
|
|
69
|
+
image_urls=images,
|
|
70
|
+
)
|
|
71
|
+
return result
|
|
72
|
+
|
|
73
|
+
|
|
37
74
|
# 页面上下文里运行的抽取脚本。直接复用 OpenCLI 的提取逻辑(DOM 文案检查 + mtop 调用)。
|
|
38
75
|
_FETCH_JS = r"""
|
|
39
76
|
(itemId) => (async () => {
|
|
@@ -131,7 +168,7 @@ _FETCH_JS = r"""
|
|
|
131
168
|
"""
|
|
132
169
|
|
|
133
170
|
|
|
134
|
-
async def
|
|
171
|
+
async def _run_native(item_id: str) -> dict[str, Any]:
|
|
135
172
|
url = _build_item_url(item_id)
|
|
136
173
|
async with goofish_page() as page:
|
|
137
174
|
await page.goto(url, wait_until="domcontentloaded")
|
|
@@ -161,14 +198,33 @@ async def _run(item_id: str) -> dict[str, Any]:
|
|
|
161
198
|
return result
|
|
162
199
|
|
|
163
200
|
|
|
201
|
+
|
|
202
|
+
async def _run(item_id: str) -> dict[str, Any]:
|
|
203
|
+
if os.environ.get("GOOFISH_DESKTOP_SANDBOX") != "1":
|
|
204
|
+
return await _run_native(item_id)
|
|
205
|
+
async with goofish_page() as page:
|
|
206
|
+
raw = await read_item_page(page, item_id)
|
|
207
|
+
result = _view_result(raw, item_id)
|
|
208
|
+
if not result.get("title"):
|
|
209
|
+
raise GoofishError(f"未拿到商品 {item_id} 的标题,接口返回为空")
|
|
210
|
+
return result
|
|
211
|
+
|
|
212
|
+
|
|
164
213
|
@command(
|
|
165
214
|
namespace="item",
|
|
166
215
|
name="view",
|
|
167
|
-
description="
|
|
216
|
+
description="浏览器视角查看商品详情(读取页面响应,含图片和卖家字段)",
|
|
168
217
|
strategy=Strategy.COOKIE,
|
|
169
218
|
columns=[
|
|
170
|
-
"item_id",
|
|
171
|
-
"
|
|
219
|
+
"item_id",
|
|
220
|
+
"title",
|
|
221
|
+
"price",
|
|
222
|
+
"condition",
|
|
223
|
+
"brand",
|
|
224
|
+
"location",
|
|
225
|
+
"seller_name",
|
|
226
|
+
"want_count",
|
|
227
|
+
"browse_count",
|
|
172
228
|
],
|
|
173
229
|
)
|
|
174
230
|
def view(item_id: str) -> dict[str, Any]:
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"""Playwright 浏览器上下文 —— 吸纳 OpenCLI 的浏览器自动化路线。
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
沙箱模式串行连接容器内的常驻 Chromium,保留同一页面和人工验证后的会话。
|
|
4
|
+
以下设计说明针对默认本机模式:
|
|
4
5
|
1. **用系统 Chrome**(`channel="chrome"`),不用 playwright 自带的 bundled chromium——
|
|
5
6
|
bundled chromium 的 UA / CDP 指纹太"裸",是风控高危目标;系统 Chrome 是真实用户
|
|
6
7
|
每天在用的可执行,配上真实 cookies 后基本等同正常浏览。
|
|
@@ -93,8 +94,11 @@ async def goofish_page(
|
|
|
93
94
|
headless: bool | None = None,
|
|
94
95
|
viewport: tuple[int, int] = (1440, 900),
|
|
95
96
|
cookies: dict | list | None = None,
|
|
97
|
+
persist_session: bool = True,
|
|
96
98
|
) -> AsyncIterator[Any]:
|
|
97
|
-
"""
|
|
99
|
+
"""本机启动独立 profile;沙箱串行连接常驻浏览器,yield 出一个 `Page`。
|
|
100
|
+
|
|
101
|
+
本机使用系统 Chrome;沙箱使用虚拟显示器上的 Chromium。
|
|
98
102
|
|
|
99
103
|
`cookies` 可选:显式传入(flat dict 或带 domain 的 records list)时直接用;
|
|
100
104
|
不传则走 `Session.load()` 三级兜底。自动刷 `_m_h5_tk` 的调用方需要用内存里
|
|
@@ -107,17 +111,28 @@ async def goofish_page(
|
|
|
107
111
|
"""
|
|
108
112
|
from playwright.async_api import async_playwright
|
|
109
113
|
|
|
114
|
+
sandbox = os.environ.get("GOOFISH_DESKTOP_SANDBOX") == "1"
|
|
115
|
+
if sandbox:
|
|
116
|
+
from goofish_cli.core.errors import GoofishError
|
|
117
|
+
if not Path("/.dockerenv").exists() or os.environ.get("DISPLAY") != ":1":
|
|
118
|
+
raise GoofishError("沙箱虚拟桌面不可用;不会回退到本机浏览器。")
|
|
119
|
+
from .sandbox_browser import sandbox_page
|
|
120
|
+
async with sandbox_page(cookies=cookies, persist_session=persist_session) as page:
|
|
121
|
+
yield page
|
|
122
|
+
return
|
|
123
|
+
|
|
110
124
|
if headless is None:
|
|
111
125
|
# 默认 headful。CI 用户显式 GOOFISH_HEADLESS=1 切回(可能触发风控)。
|
|
112
126
|
headless = os.environ.get("GOOFISH_HEADLESS") == "1"
|
|
113
127
|
|
|
114
|
-
|
|
115
|
-
# 每次调用独立 profile 目录,避开 Chrome SingletonLock 并发冲突
|
|
116
|
-
profile_dir = Path(tempfile.mkdtemp(prefix="chrome-", dir=str(PROFILES_PARENT)))
|
|
128
|
+
profiles_parent = PROFILES_PARENT
|
|
117
129
|
if cookies is None:
|
|
118
130
|
cookies = _load_cookies_from_session()
|
|
119
131
|
pw_cookies = _cookies_to_playwright(cookies)
|
|
120
132
|
|
|
133
|
+
profiles_parent.mkdir(parents=True, exist_ok=True)
|
|
134
|
+
# 登录态解析失败时不创建 profile;成功后每次调用独立目录,避开 SingletonLock。
|
|
135
|
+
profile_dir = Path(tempfile.mkdtemp(prefix="chrome-", dir=str(profiles_parent)))
|
|
121
136
|
try:
|
|
122
137
|
async with async_playwright() as pw:
|
|
123
138
|
context = await pw.chromium.launch_persistent_context(
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"""读取详情页自身发出的响应,校验请求和返回的商品身份。"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import json
|
|
7
|
+
import re
|
|
8
|
+
from typing import Any
|
|
9
|
+
from urllib.parse import parse_qs, urlsplit
|
|
10
|
+
|
|
11
|
+
from .errors import GoofishError, RiskControlError
|
|
12
|
+
from .item_data import normalize_item
|
|
13
|
+
from .mtop import _classify_error
|
|
14
|
+
|
|
15
|
+
DETAIL_PATH = "/h5/mtop.taobao.idle.pc.detail/1.0/"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _matches_request(request, item_id: str) -> bool:
|
|
19
|
+
url = urlsplit(request.url)
|
|
20
|
+
if url.hostname not in {"h5api.m.goofish.com", "h5api.m.taobao.com"} or url.path != DETAIL_PATH:
|
|
21
|
+
return False
|
|
22
|
+
try:
|
|
23
|
+
fields = parse_qs(request.post_data or "")
|
|
24
|
+
if "data" not in fields:
|
|
25
|
+
fields = parse_qs(url.query)
|
|
26
|
+
return str(json.loads(fields["data"][0]).get("itemId")) == item_id
|
|
27
|
+
except (ValueError, KeyError, TypeError, AttributeError):
|
|
28
|
+
return False
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _decode_response(text: str, item_id: str) -> dict:
|
|
32
|
+
if not text.lstrip().startswith("{"):
|
|
33
|
+
match = re.fullmatch(r"\s*[\w.$]+\s*\((.*)\)\s*;?\s*", text, re.S)
|
|
34
|
+
if not match:
|
|
35
|
+
raise GoofishError("详情响应不是可确认的 JSON/JSONP")
|
|
36
|
+
text = match[1]
|
|
37
|
+
try:
|
|
38
|
+
raw = json.loads(text)
|
|
39
|
+
except ValueError as exc:
|
|
40
|
+
raise GoofishError("详情响应无法解析") from exc
|
|
41
|
+
if not isinstance(raw, dict) or not isinstance(raw.get("ret"), list) or not raw["ret"]:
|
|
42
|
+
raise GoofishError("详情响应缺少明确的业务状态")
|
|
43
|
+
if not all(isinstance(value, str) for value in raw["ret"]):
|
|
44
|
+
raise GoofishError("详情响应业务状态格式无效")
|
|
45
|
+
try:
|
|
46
|
+
_classify_error(raw, "mtop.taobao.idle.pc.detail")
|
|
47
|
+
except RiskControlError as exc:
|
|
48
|
+
raise RiskControlError(
|
|
49
|
+
"闲鱼详情需要人工验证;请在沙箱浏览器完成验证后重试,不会自动绕过或重发请求",
|
|
50
|
+
raw=raw,
|
|
51
|
+
) from exc
|
|
52
|
+
if any(value.partition("::")[0] != "SUCCESS" for value in raw["ret"]):
|
|
53
|
+
raise GoofishError("详情响应不是明确成功状态")
|
|
54
|
+
normalize_item(raw, item_id)
|
|
55
|
+
return raw
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class ItemResponse:
|
|
59
|
+
"""只消费本次观察到的匹配请求,忽略推荐、验证端点和迟到的旧请求。"""
|
|
60
|
+
|
|
61
|
+
def __init__(self, page, item_id: str):
|
|
62
|
+
self.page = page
|
|
63
|
+
self.item_id = item_id
|
|
64
|
+
self.raw: dict | None = None
|
|
65
|
+
self.error: GoofishError | None = None
|
|
66
|
+
self.ready = asyncio.Event()
|
|
67
|
+
self.requests: set[Any] = set()
|
|
68
|
+
self.tasks: set[asyncio.Task] = set()
|
|
69
|
+
self.request_handler = self._request
|
|
70
|
+
self.response_handler = self._schedule
|
|
71
|
+
page.on("request", self.request_handler)
|
|
72
|
+
page.on("response", self.response_handler)
|
|
73
|
+
|
|
74
|
+
def _request(self, request) -> None:
|
|
75
|
+
if _matches_request(request, self.item_id):
|
|
76
|
+
self.requests.add(request)
|
|
77
|
+
|
|
78
|
+
def _schedule(self, response) -> None:
|
|
79
|
+
if response.request not in self.requests:
|
|
80
|
+
return
|
|
81
|
+
self.requests.discard(response.request)
|
|
82
|
+
task = asyncio.create_task(self._capture(response))
|
|
83
|
+
self.tasks.add(task)
|
|
84
|
+
task.add_done_callback(self.tasks.discard)
|
|
85
|
+
|
|
86
|
+
async def _capture(self, response) -> None:
|
|
87
|
+
try:
|
|
88
|
+
if response.status != 200:
|
|
89
|
+
raise GoofishError(f"详情服务返回 HTTP {response.status}")
|
|
90
|
+
self.raw = _decode_response(await response.text(), self.item_id)
|
|
91
|
+
self.error = None
|
|
92
|
+
except GoofishError as exc:
|
|
93
|
+
self.raw = None
|
|
94
|
+
self.error = exc
|
|
95
|
+
except Exception:
|
|
96
|
+
self.raw = None
|
|
97
|
+
self.error = GoofishError("详情响应读取失败")
|
|
98
|
+
self.ready.set()
|
|
99
|
+
|
|
100
|
+
async def wait(self, timeout: float = 20, *, allow_verification: bool = False) -> dict:
|
|
101
|
+
deadline = asyncio.get_running_loop().time() + timeout
|
|
102
|
+
while True:
|
|
103
|
+
try:
|
|
104
|
+
await asyncio.wait_for(
|
|
105
|
+
self.ready.wait(), max(0.01, deadline - asyncio.get_running_loop().time())
|
|
106
|
+
)
|
|
107
|
+
except TimeoutError as exc:
|
|
108
|
+
raise GoofishError(
|
|
109
|
+
"未收到目标商品的成功详情响应;沙箱页面保留,可检查当前页面"
|
|
110
|
+
) from exc
|
|
111
|
+
self.ready.clear()
|
|
112
|
+
if self.raw is not None:
|
|
113
|
+
return self.raw
|
|
114
|
+
if self.error is not None:
|
|
115
|
+
if allow_verification and isinstance(self.error, RiskControlError):
|
|
116
|
+
self.error = None
|
|
117
|
+
continue
|
|
118
|
+
raise self.error
|
|
119
|
+
|
|
120
|
+
async def close(self) -> None:
|
|
121
|
+
self.page.remove_listener("request", self.request_handler)
|
|
122
|
+
self.page.remove_listener("response", self.response_handler)
|
|
123
|
+
for task in self.tasks:
|
|
124
|
+
task.cancel()
|
|
125
|
+
await asyncio.gather(*self.tasks, return_exceptions=True)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
async def read_item_page(page, item_id: str) -> dict:
|
|
129
|
+
observer = ItemResponse(page, item_id)
|
|
130
|
+
try:
|
|
131
|
+
await page.goto(f"https://www.goofish.com/item?id={item_id}", wait_until="domcontentloaded")
|
|
132
|
+
return await observer.wait()
|
|
133
|
+
finally:
|
|
134
|
+
await observer.close()
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
async def fetch_item_page(item_id: str) -> dict:
|
|
138
|
+
from .browser import goofish_page
|
|
139
|
+
|
|
140
|
+
async with goofish_page() as page:
|
|
141
|
+
return await read_item_page(page, item_id)
|
|
@@ -27,11 +27,16 @@ def read_json(path: Path) -> dict[str, Any]:
|
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
def atomic_write(path: Path, value: dict[str, Any]) -> None:
|
|
30
|
+
atomic_write_bytes(path, json.dumps(value, allow_nan=False).encode())
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def atomic_write_bytes(path: Path, value: bytes) -> None:
|
|
34
|
+
"""同目录写入并原子替换;明文或加密状态都不暴露半份文件。"""
|
|
30
35
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
31
36
|
fd, temporary = tempfile.mkstemp(prefix=path.name + ".", dir=path.parent)
|
|
32
37
|
try:
|
|
33
|
-
with os.fdopen(fd, "
|
|
34
|
-
|
|
38
|
+
with os.fdopen(fd, "wb") as stream:
|
|
39
|
+
stream.write(value)
|
|
35
40
|
stream.flush()
|
|
36
41
|
os.fsync(stream.fileno())
|
|
37
42
|
os.chmod(temporary, 0o600)
|