twitter-cli 0.1.0__tar.gz → 0.2.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.
Files changed (31) hide show
  1. twitter_cli-0.2.0/.github/workflows/publish-clawhub.yml +59 -0
  2. twitter_cli-0.2.0/PKG-INFO +407 -0
  3. twitter_cli-0.2.0/README.md +371 -0
  4. twitter_cli-0.2.0/SKILL.md +154 -0
  5. twitter_cli-0.2.0/config.yaml +21 -0
  6. {twitter_cli-0.1.0 → twitter_cli-0.2.0}/pyproject.toml +5 -1
  7. {twitter_cli-0.1.0 → twitter_cli-0.2.0}/tests/test_cli.py +1 -1
  8. {twitter_cli-0.1.0 → twitter_cli-0.2.0}/tests/test_config_normalization.py +27 -0
  9. {twitter_cli-0.1.0 → twitter_cli-0.2.0}/twitter_cli/auth.py +18 -29
  10. twitter_cli-0.2.0/twitter_cli/cli.py +512 -0
  11. twitter_cli-0.2.0/twitter_cli/client.py +1004 -0
  12. {twitter_cli-0.1.0 → twitter_cli-0.2.0}/twitter_cli/config.py +17 -0
  13. twitter_cli-0.2.0/twitter_cli/constants.py +17 -0
  14. {twitter_cli-0.1.0 → twitter_cli-0.2.0}/twitter_cli/filter.py +1 -23
  15. {twitter_cli-0.1.0 → twitter_cli-0.2.0}/twitter_cli/formatter.py +0 -9
  16. {twitter_cli-0.1.0 → twitter_cli-0.2.0}/twitter_cli/serialization.py +30 -2
  17. {twitter_cli-0.1.0 → twitter_cli-0.2.0}/uv.lock +542 -1
  18. twitter_cli-0.1.0/PKG-INFO +0 -185
  19. twitter_cli-0.1.0/README.md +0 -153
  20. twitter_cli-0.1.0/config.yaml +0 -15
  21. twitter_cli-0.1.0/twitter_cli/cli.py +0 -245
  22. twitter_cli-0.1.0/twitter_cli/client.py +0 -586
  23. {twitter_cli-0.1.0 → twitter_cli-0.2.0}/.github/workflows/ci.yml +0 -0
  24. {twitter_cli-0.1.0 → twitter_cli-0.2.0}/.github/workflows/publish.yml +0 -0
  25. {twitter_cli-0.1.0 → twitter_cli-0.2.0}/.gitignore +0 -0
  26. {twitter_cli-0.1.0 → twitter_cli-0.2.0}/tests/conftest.py +0 -0
  27. {twitter_cli-0.1.0 → twitter_cli-0.2.0}/tests/test_config.py +0 -0
  28. {twitter_cli-0.1.0 → twitter_cli-0.2.0}/tests/test_filter.py +0 -0
  29. {twitter_cli-0.1.0 → twitter_cli-0.2.0}/tests/test_serialization.py +0 -0
  30. {twitter_cli-0.1.0 → twitter_cli-0.2.0}/twitter_cli/__init__.py +0 -0
  31. {twitter_cli-0.1.0 → twitter_cli-0.2.0}/twitter_cli/models.py +0 -0
@@ -0,0 +1,59 @@
1
+ name: Publish to ClawHub
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "v*"
7
+ workflow_dispatch:
8
+
9
+ jobs:
10
+ publish:
11
+ runs-on: ubuntu-latest
12
+ permissions:
13
+ contents: read
14
+ env:
15
+ CLAWHUB_SLUG: twitter-cli
16
+ CLAWHUB_NAME: twitter-cli
17
+
18
+ steps:
19
+ - uses: actions/checkout@v4
20
+
21
+ - uses: actions/setup-node@v4
22
+ with:
23
+ node-version: "20"
24
+
25
+ - name: Install ClawHub CLI
26
+ run: npm install -g clawhub@0.7.0
27
+
28
+ - name: Publish to ClawHub
29
+ env:
30
+ CLAWHUB_TOKEN: ${{ secrets.CLAWHUB_TOKEN }}
31
+ run: |
32
+ if [ -z "${CLAWHUB_TOKEN:-}" ]; then
33
+ echo "Missing required secret: CLAWHUB_TOKEN"
34
+ exit 1
35
+ fi
36
+
37
+ if [ "${GITHUB_REF_TYPE:-}" = "tag" ] && [ -n "${GITHUB_REF_NAME:-}" ]; then
38
+ VERSION="${GITHUB_REF_NAME#v}"
39
+ else
40
+ VERSION="$(sed -n 's/^version = \"\([^\"]*\)\"/\1/p' pyproject.toml | head -n 1)"
41
+ fi
42
+ if [ -z "${VERSION:-}" ]; then
43
+ echo "Unable to resolve version"
44
+ exit 1
45
+ fi
46
+ echo "Publishing ${CLAWHUB_SLUG}@${VERSION}"
47
+
48
+ if clawhub --no-input inspect "${CLAWHUB_SLUG}" --version "${VERSION}" >/dev/null 2>&1; then
49
+ echo "Version ${VERSION} already exists on ClawHub, skipping publish."
50
+ exit 0
51
+ fi
52
+
53
+ clawhub --no-input login --token "${CLAWHUB_TOKEN}" --no-browser
54
+ clawhub --no-input publish . \
55
+ --slug "${CLAWHUB_SLUG}" \
56
+ --name "${CLAWHUB_NAME}" \
57
+ --version "${VERSION}" \
58
+ --changelog "Release ${VERSION}" \
59
+ --tags latest
@@ -0,0 +1,407 @@
1
+ Metadata-Version: 2.4
2
+ Name: twitter-cli
3
+ Version: 0.2.0
4
+ Summary: A CLI for Twitter/X — feed, bookmarks, and user timeline in terminal
5
+ Project-URL: Homepage, https://github.com/jackwener/twitter-cli
6
+ Project-URL: Repository, https://github.com/jackwener/twitter-cli
7
+ Project-URL: Issues, https://github.com/jackwener/twitter-cli/issues
8
+ Author-email: jackwener <jakevingoo@gmail.com>
9
+ License-Expression: Apache-2.0
10
+ Keywords: cli,feed,timeline,twitter,x
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: Apache Software License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.8
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Topic :: Utilities
23
+ Requires-Python: >=3.8
24
+ Requires-Dist: beautifulsoup4>=4.12
25
+ Requires-Dist: browser-cookie3>=0.19
26
+ Requires-Dist: click>=8.0
27
+ Requires-Dist: curl-cffi>=0.7
28
+ Requires-Dist: pyyaml>=6.0
29
+ Requires-Dist: requests>=2.32.4
30
+ Requires-Dist: rich>=13.0
31
+ Requires-Dist: xclienttransaction>=1.0.1
32
+ Provides-Extra: dev
33
+ Requires-Dist: pytest>=8.0; extra == 'dev'
34
+ Requires-Dist: ruff>=0.8; extra == 'dev'
35
+ Description-Content-Type: text/markdown
36
+
37
+ # twitter-cli
38
+
39
+ [![CI](https://github.com/jackwener/twitter-cli/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/jackwener/twitter-cli/actions/workflows/ci.yml)
40
+ [![PyPI version](https://img.shields.io/pypi/v/twitter-cli.svg)](https://pypi.org/project/twitter-cli/)
41
+ [![Python versions](https://img.shields.io/pypi/pyversions/twitter-cli.svg)](https://pypi.org/project/twitter-cli/)
42
+
43
+ A terminal-first CLI for Twitter/X: read timelines, bookmarks, and user profiles without API keys.
44
+
45
+ ## More Tools
46
+
47
+ - [xhs-cli](https://github.com/jackwener/xhs-cli) — Xiaohongshu (小红书) CLI for notes and account workflows
48
+ - [bilibili-cli](https://github.com/jackwener/bilibili-cli) — Bilibili CLI for videos, users, search, and feeds
49
+
50
+ [English](#english) | [中文](#中文)
51
+
52
+ ## English
53
+
54
+ ### Features
55
+
56
+ **Read:**
57
+ - Timeline: fetch `for-you` and `following` feeds
58
+ - Bookmarks: list saved tweets from your account
59
+ - Search: find tweets by keyword with Top/Latest/Photos/Videos tabs
60
+ - Tweet detail: view a tweet and its replies
61
+ - List timeline: fetch tweets from a Twitter List
62
+ - User lookup: fetch user profile, tweets, likes, followers, and following
63
+ - JSON output: export any data for scripting
64
+ - Optional scoring filter: rank tweets by engagement weights
65
+
66
+ **Write:**
67
+ - Post: create new tweets and replies
68
+ - Delete: remove your own tweets
69
+ - Like / Unlike: manage tweet likes
70
+ - Retweet / Unretweet: manage retweets
71
+ - Bookmark: favorite/unfavorite
72
+
73
+ **Auth:**
74
+ - Cookie auth: use browser cookies or environment variables
75
+
76
+ ### Installation
77
+
78
+ ```bash
79
+ # Recommended: uv tool (fast, isolated)
80
+ uv tool install twitter-cli
81
+
82
+ # Alternative: pipx
83
+ pipx install twitter-cli
84
+ ```
85
+
86
+ Install from source:
87
+
88
+ ```bash
89
+ git clone git@github.com:jackwener/twitter-cli.git
90
+ cd twitter-cli
91
+ uv sync
92
+ ```
93
+
94
+ ### Quick Start
95
+
96
+ ```bash
97
+ # Fetch home timeline (For You)
98
+ twitter feed
99
+
100
+ # Fetch Following timeline
101
+ twitter feed -t following
102
+
103
+ # Enable ranking filter explicitly
104
+ twitter feed --filter
105
+ ```
106
+
107
+ ### Usage
108
+
109
+ ```bash
110
+ # Feed
111
+ twitter feed --max 50
112
+ twitter feed --json > tweets.json
113
+ twitter feed --input tweets.json
114
+
115
+ # Bookmarks
116
+ twitter favorites
117
+ twitter favorites --max 30 --json
118
+
119
+ # Search
120
+ twitter search "Claude Code"
121
+ twitter search "AI agent" -t Latest --max 50
122
+ twitter search "机器学习" --json
123
+
124
+ # Tweet detail (view tweet + replies)
125
+ twitter tweet 1234567890
126
+ twitter tweet https://x.com/user/status/1234567890
127
+
128
+ # List timeline
129
+ twitter list 1539453138322673664
130
+
131
+ # User
132
+ twitter user elonmusk
133
+ twitter user-posts elonmusk --max 20
134
+ twitter likes elonmusk --max 30
135
+ twitter followers elonmusk --max 50
136
+ twitter following elonmusk --max 50
137
+
138
+ # Write operations
139
+ twitter post "Hello from twitter-cli!"
140
+ twitter post "reply text" --reply-to 1234567890
141
+ twitter delete 1234567890
142
+ twitter like 1234567890
143
+ twitter unlike 1234567890
144
+ twitter retweet 1234567890
145
+ twitter unretweet 1234567890
146
+ twitter favorite 1234567890
147
+ twitter unfavorite 1234567890
148
+ ```
149
+
150
+ ### Authentication
151
+
152
+ twitter-cli uses this auth priority:
153
+
154
+ 1. Environment variables: `TWITTER_AUTH_TOKEN` + `TWITTER_CT0`
155
+ 2. Browser cookies: auto-extract from Chrome/Edge/Firefox/Brave
156
+
157
+ After loading cookies, the CLI performs lightweight verification. Commands that require account access fail fast on clear auth errors (`401/403`).
158
+
159
+ ### Configuration
160
+
161
+ Create `config.yaml` in your working directory:
162
+
163
+ ```yaml
164
+ fetch:
165
+ count: 50
166
+
167
+ filter:
168
+ mode: "topN" # "topN" | "score" | "all"
169
+ topN: 20
170
+ minScore: 50
171
+ lang: []
172
+ excludeRetweets: false
173
+ weights:
174
+ likes: 1.0
175
+ retweets: 3.0
176
+ replies: 2.0
177
+ bookmarks: 5.0
178
+ views_log: 0.5
179
+
180
+ rateLimit:
181
+ requestDelay: 1.5 # seconds between paginated requests
182
+ maxRetries: 3 # retry count on rate limit (429)
183
+ retryBaseDelay: 5.0 # base delay for exponential backoff
184
+ maxCount: 200 # hard cap on fetched items
185
+ ```
186
+
187
+ Filter behavior:
188
+
189
+ - Default behavior: no ranking filter unless `--filter` is passed
190
+ - With `--filter`: tweets are scored/sorted using `config.filter`
191
+
192
+ Scoring formula:
193
+
194
+ ```text
195
+ score = likes_w * likes
196
+ + retweets_w * retweets
197
+ + replies_w * replies
198
+ + bookmarks_w * bookmarks
199
+ + views_log_w * log10(max(views, 1))
200
+ ```
201
+
202
+ Mode behavior:
203
+
204
+ - `mode: "topN"` keeps the highest `topN` tweets by score
205
+ - `mode: "score"` keeps tweets where `score >= minScore`
206
+ - `mode: "all"` returns all tweets after sorting by score
207
+
208
+ ### Troubleshooting
209
+
210
+ - `No Twitter cookies found`
211
+ - Ensure you are logged in to `x.com` in a supported browser.
212
+ - Or set `TWITTER_AUTH_TOKEN` and `TWITTER_CT0` manually.
213
+
214
+ - `Cookie expired or invalid (HTTP 401/403)`
215
+ - Re-login to `x.com` and retry.
216
+
217
+ - `Twitter API error 404`
218
+ - This can happen when upstream GraphQL query IDs rotate.
219
+ - Retry the command; the client attempts a live queryId fallback.
220
+
221
+ - `Invalid tweet JSON file`
222
+ - Regenerate input using `twitter feed --json > tweets.json`.
223
+
224
+ ### Development
225
+
226
+ ```bash
227
+ # Install dev dependencies
228
+ uv sync --extra dev
229
+
230
+ # Lint + tests
231
+ uv run ruff check .
232
+ uv run pytest -q
233
+ ```
234
+
235
+ ### Project Structure
236
+
237
+ ```text
238
+ twitter_cli/
239
+ ├── __init__.py
240
+ ├── cli.py
241
+ ├── client.py
242
+ ├── auth.py
243
+ ├── config.py
244
+ ├── constants.py
245
+ ├── filter.py
246
+ ├── formatter.py
247
+ ├── serialization.py
248
+ └── models.py
249
+ ```
250
+
251
+ ### Use as AI Agent Skill
252
+
253
+ twitter-cli ships with a [`SKILL.md`](./SKILL.md) so AI agents can execute common X/Twitter workflows.
254
+
255
+ #### Claude Code / Antigravity
256
+
257
+ ```bash
258
+ # Clone into your project's skills directory
259
+ mkdir -p .agents/skills
260
+ git clone git@github.com:jackwener/twitter-cli.git .agents/skills/twitter-cli
261
+
262
+ # Or copy SKILL.md only
263
+ curl -o .agents/skills/twitter-cli/SKILL.md \
264
+ https://raw.githubusercontent.com/jackwener/twitter-cli/main/SKILL.md
265
+ ```
266
+
267
+ #### OpenClaw / ClawHub
268
+
269
+ Install from ClawHub:
270
+
271
+ ```bash
272
+ clawhub install twitter-cli
273
+ ```
274
+
275
+ After installation, OpenClaw can call `twitter-cli` commands directly.
276
+
277
+ ## 中文
278
+
279
+ ### 功能概览
280
+
281
+ **读取:**
282
+ - 时间线读取:支持 `for-you` 和 `following`
283
+ - 收藏读取:查看账号书签推文
284
+ - 搜索:按关键词搜索推文,支持 Top/Latest/Photos/Videos
285
+ - 推文详情:查看推文及其回复
286
+ - 列表时间线:获取 Twitter List 的推文
287
+ - 用户查询:查看用户资料、推文、点赞、粉丝和关注
288
+ - JSON 输出:便于脚本处理
289
+
290
+ **写入:**
291
+ - 发推:发布新推文和回复
292
+ - 删除:删除自己的推文
293
+ - 点赞 / 取消点赞
294
+ - 转推 / 取消转推
295
+ - 收藏 / 取消收藏:favorite/unfavorite
296
+
297
+ - 可选筛选:按 engagement score 排序
298
+ - Cookie 认证:支持环境变量和浏览器自动提取
299
+
300
+ ### 安装
301
+
302
+ ```bash
303
+ # 推荐:uv tool
304
+ uv tool install twitter-cli
305
+ ```
306
+
307
+ ### 使用指南
308
+
309
+ ```bash
310
+ # 时间线
311
+ twitter feed
312
+ twitter feed -t following
313
+ twitter feed --filter
314
+
315
+ # 收藏
316
+ twitter favorites
317
+
318
+ # 搜索
319
+ twitter search "Claude Code"
320
+ twitter search "AI agent" -t Latest --max 50
321
+
322
+ # 推文详情
323
+ twitter tweet 1234567890
324
+
325
+ # 列表时间线
326
+ twitter list 1539453138322673664
327
+
328
+ # 用户
329
+ twitter user elonmusk
330
+ twitter user-posts elonmusk --max 20
331
+ twitter likes elonmusk --max 30
332
+ twitter followers elonmusk
333
+ twitter following elonmusk
334
+
335
+ # 写操作
336
+ twitter post "你好,世界!"
337
+ twitter post "回复内容" --reply-to 1234567890
338
+ twitter delete 1234567890
339
+ twitter like 1234567890
340
+ twitter unlike 1234567890
341
+ twitter retweet 1234567890
342
+ twitter unretweet 1234567890
343
+ twitter favorite 1234567890
344
+ twitter unfavorite 1234567890
345
+ ```
346
+
347
+ ### 认证说明
348
+
349
+ 认证优先级:
350
+
351
+ 1. `TWITTER_AUTH_TOKEN` + `TWITTER_CT0`
352
+ 2. 浏览器 Cookie 自动提取(Chrome/Edge/Firefox/Brave)
353
+
354
+ ### 筛选算法
355
+
356
+ 只有在传入 `--filter` 时才会启用筛选评分;默认不筛选。
357
+
358
+ 评分公式:
359
+
360
+ ```text
361
+ score = likes_w * likes
362
+ + retweets_w * retweets
363
+ + replies_w * replies
364
+ + bookmarks_w * bookmarks
365
+ + views_log_w * log10(max(views, 1))
366
+ ```
367
+
368
+ 模式说明:
369
+
370
+ - `mode: "topN"`:按分数排序后保留前 `topN` 条
371
+ - `mode: "score"`:仅保留 `score >= minScore` 的推文
372
+ - `mode: "all"`:按分数排序后全部保留
373
+
374
+ ### 常见问题
375
+
376
+ - 报错 `No Twitter cookies found`:请先登录 `x.com` 或手动设置环境变量。
377
+ - 报错 `Cookie expired or invalid`:Cookie 过期,重新登录后重试。
378
+ - 报错 `Twitter API error 404`:通常是 queryId 轮换,重试即可。
379
+
380
+ ### 注意事项
381
+
382
+ - Cookie 登录有平台风控风险,建议使用专用账号。
383
+ - Cookie 仅在本地使用,不会被本工具上传。
384
+
385
+ ### 作为 AI Agent Skill 使用
386
+
387
+ twitter-cli 提供了 [`SKILL.md`](./SKILL.md),可让 AI Agent 更稳定地调用本工具。
388
+
389
+ #### Claude Code / Antigravity
390
+
391
+ ```bash
392
+ # 克隆到项目 skills 目录
393
+ mkdir -p .agents/skills
394
+ git clone git@github.com:jackwener/twitter-cli.git .agents/skills/twitter-cli
395
+
396
+ # 或仅下载 SKILL.md
397
+ curl -o .agents/skills/twitter-cli/SKILL.md \
398
+ https://raw.githubusercontent.com/jackwener/twitter-cli/main/SKILL.md
399
+ ```
400
+
401
+ #### OpenClaw / ClawHub
402
+
403
+ 通过 ClawHub 安装:
404
+
405
+ ```bash
406
+ clawhub install twitter-cli
407
+ ```