twitter-cli 0.4.4__tar.gz → 0.4.6__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.
- {twitter_cli-0.4.4 → twitter_cli-0.4.6}/PKG-INFO +13 -3
- {twitter_cli-0.4.4 → twitter_cli-0.4.6}/README.md +12 -2
- {twitter_cli-0.4.4 → twitter_cli-0.4.6}/SKILL.md +9 -1
- {twitter_cli-0.4.4 → twitter_cli-0.4.6}/pyproject.toml +1 -1
- {twitter_cli-0.4.4 → twitter_cli-0.4.6}/twitter_cli/auth.py +73 -3
- {twitter_cli-0.4.4 → twitter_cli-0.4.6}/twitter_cli/cli.py +13 -7
- {twitter_cli-0.4.4 → twitter_cli-0.4.6}/uv.lock +1 -1
- {twitter_cli-0.4.4 → twitter_cli-0.4.6}/.github/workflows/ci.yml +0 -0
- {twitter_cli-0.4.4 → twitter_cli-0.4.6}/.github/workflows/publish-clawhub.yml +0 -0
- {twitter_cli-0.4.4 → twitter_cli-0.4.6}/.github/workflows/publish.yml +0 -0
- {twitter_cli-0.4.4 → twitter_cli-0.4.6}/.gitignore +0 -0
- {twitter_cli-0.4.4 → twitter_cli-0.4.6}/LICENSE +0 -0
- {twitter_cli-0.4.4 → twitter_cli-0.4.6}/config.yaml +0 -0
- {twitter_cli-0.4.4 → twitter_cli-0.4.6}/tests/conftest.py +0 -0
- {twitter_cli-0.4.4 → twitter_cli-0.4.6}/tests/test_cli.py +0 -0
- {twitter_cli-0.4.4 → twitter_cli-0.4.6}/tests/test_client.py +0 -0
- {twitter_cli-0.4.4 → twitter_cli-0.4.6}/tests/test_config.py +0 -0
- {twitter_cli-0.4.4 → twitter_cli-0.4.6}/tests/test_config_normalization.py +0 -0
- {twitter_cli-0.4.4 → twitter_cli-0.4.6}/tests/test_filter.py +0 -0
- {twitter_cli-0.4.4 → twitter_cli-0.4.6}/tests/test_serialization.py +0 -0
- {twitter_cli-0.4.4 → twitter_cli-0.4.6}/twitter_cli/__init__.py +0 -0
- {twitter_cli-0.4.4 → twitter_cli-0.4.6}/twitter_cli/client.py +0 -0
- {twitter_cli-0.4.4 → twitter_cli-0.4.6}/twitter_cli/config.py +0 -0
- {twitter_cli-0.4.4 → twitter_cli-0.4.6}/twitter_cli/constants.py +0 -0
- {twitter_cli-0.4.4 → twitter_cli-0.4.6}/twitter_cli/filter.py +0 -0
- {twitter_cli-0.4.4 → twitter_cli-0.4.6}/twitter_cli/formatter.py +0 -0
- {twitter_cli-0.4.4 → twitter_cli-0.4.6}/twitter_cli/models.py +0 -0
- {twitter_cli-0.4.4 → twitter_cli-0.4.6}/twitter_cli/serialization.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: twitter-cli
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.6
|
|
4
4
|
Summary: A CLI for Twitter/X — feed, bookmarks, and user timeline in terminal
|
|
5
5
|
Project-URL: Homepage, https://github.com/jackwener/twitter-cli
|
|
6
6
|
Project-URL: Repository, https://github.com/jackwener/twitter-cli
|
|
@@ -73,9 +73,10 @@ A terminal-first CLI for Twitter/X: read timelines, bookmarks, and user profiles
|
|
|
73
73
|
**Auth & Anti-Detection:**
|
|
74
74
|
- Cookie auth: use browser cookies or environment variables
|
|
75
75
|
- Full cookie forwarding: extracts ALL browser cookies for true browser fingerprint
|
|
76
|
-
- TLS fingerprint impersonation: `curl_cffi` with Chrome
|
|
76
|
+
- TLS fingerprint impersonation: `curl_cffi` with dynamic Chrome version matching
|
|
77
77
|
- `x-client-transaction-id` header generation
|
|
78
78
|
- Request timing jitter to avoid pattern detection
|
|
79
|
+
- Write operation delays (1.5–4s random) to mitigate rate limits
|
|
79
80
|
- Proxy support via `TWITTER_PROXY` environment variable
|
|
80
81
|
|
|
81
82
|
### Installation
|
|
@@ -125,6 +126,8 @@ twitter favorites --max 30 --json
|
|
|
125
126
|
twitter search "Claude Code"
|
|
126
127
|
twitter search "AI agent" -t Latest --max 50
|
|
127
128
|
twitter search "机器学习" --json
|
|
129
|
+
twitter search "topic" -o results.json # Save to file
|
|
130
|
+
twitter search "trending" --filter # Apply ranking filter
|
|
128
131
|
|
|
129
132
|
# Tweet detail (view tweet + replies)
|
|
130
133
|
twitter tweet 1234567890
|
|
@@ -136,7 +139,9 @@ twitter list 1539453138322673664
|
|
|
136
139
|
# User
|
|
137
140
|
twitter user elonmusk
|
|
138
141
|
twitter user-posts elonmusk --max 20
|
|
142
|
+
twitter user-posts elonmusk -o tweets.json
|
|
139
143
|
twitter likes elonmusk --max 30
|
|
144
|
+
twitter likes elonmusk -o likes.json
|
|
140
145
|
twitter followers elonmusk --max 50
|
|
141
146
|
twitter following elonmusk --max 50
|
|
142
147
|
|
|
@@ -326,9 +331,10 @@ After installation, OpenClaw can call `twitter-cli` commands directly.
|
|
|
326
331
|
**认证与反风控:**
|
|
327
332
|
- Cookie 认证:支持环境变量和浏览器自动提取
|
|
328
333
|
- 完整 Cookie 转发:提取浏览器中所有 Twitter Cookie
|
|
329
|
-
- TLS 指纹伪装:`curl_cffi` Chrome
|
|
334
|
+
- TLS 指纹伪装:`curl_cffi` 动态匹配 Chrome 版本
|
|
330
335
|
- `x-client-transaction-id` 请求头生成
|
|
331
336
|
- 请求时序随机化(jitter)
|
|
337
|
+
- 写操作随机延迟(1.5–4 秒),降低频率风控
|
|
332
338
|
- 代理支持:`TWITTER_PROXY` 环境变量
|
|
333
339
|
|
|
334
340
|
### 安装
|
|
@@ -352,6 +358,8 @@ twitter favorites
|
|
|
352
358
|
# 搜索
|
|
353
359
|
twitter search "Claude Code"
|
|
354
360
|
twitter search "AI agent" -t Latest --max 50
|
|
361
|
+
twitter search "topic" -o results.json # 保存到文件
|
|
362
|
+
twitter search "trending" --filter # 启用排序筛选
|
|
355
363
|
|
|
356
364
|
# 推文详情
|
|
357
365
|
twitter tweet 1234567890
|
|
@@ -362,7 +370,9 @@ twitter list 1539453138322673664
|
|
|
362
370
|
# 用户
|
|
363
371
|
twitter user elonmusk
|
|
364
372
|
twitter user-posts elonmusk --max 20
|
|
373
|
+
twitter user-posts elonmusk -o tweets.json
|
|
365
374
|
twitter likes elonmusk --max 30
|
|
375
|
+
twitter likes elonmusk -o likes.json
|
|
366
376
|
twitter followers elonmusk
|
|
367
377
|
twitter following elonmusk
|
|
368
378
|
|
|
@@ -37,9 +37,10 @@ A terminal-first CLI for Twitter/X: read timelines, bookmarks, and user profiles
|
|
|
37
37
|
**Auth & Anti-Detection:**
|
|
38
38
|
- Cookie auth: use browser cookies or environment variables
|
|
39
39
|
- Full cookie forwarding: extracts ALL browser cookies for true browser fingerprint
|
|
40
|
-
- TLS fingerprint impersonation: `curl_cffi` with Chrome
|
|
40
|
+
- TLS fingerprint impersonation: `curl_cffi` with dynamic Chrome version matching
|
|
41
41
|
- `x-client-transaction-id` header generation
|
|
42
42
|
- Request timing jitter to avoid pattern detection
|
|
43
|
+
- Write operation delays (1.5–4s random) to mitigate rate limits
|
|
43
44
|
- Proxy support via `TWITTER_PROXY` environment variable
|
|
44
45
|
|
|
45
46
|
### Installation
|
|
@@ -89,6 +90,8 @@ twitter favorites --max 30 --json
|
|
|
89
90
|
twitter search "Claude Code"
|
|
90
91
|
twitter search "AI agent" -t Latest --max 50
|
|
91
92
|
twitter search "机器学习" --json
|
|
93
|
+
twitter search "topic" -o results.json # Save to file
|
|
94
|
+
twitter search "trending" --filter # Apply ranking filter
|
|
92
95
|
|
|
93
96
|
# Tweet detail (view tweet + replies)
|
|
94
97
|
twitter tweet 1234567890
|
|
@@ -100,7 +103,9 @@ twitter list 1539453138322673664
|
|
|
100
103
|
# User
|
|
101
104
|
twitter user elonmusk
|
|
102
105
|
twitter user-posts elonmusk --max 20
|
|
106
|
+
twitter user-posts elonmusk -o tweets.json
|
|
103
107
|
twitter likes elonmusk --max 30
|
|
108
|
+
twitter likes elonmusk -o likes.json
|
|
104
109
|
twitter followers elonmusk --max 50
|
|
105
110
|
twitter following elonmusk --max 50
|
|
106
111
|
|
|
@@ -290,9 +295,10 @@ After installation, OpenClaw can call `twitter-cli` commands directly.
|
|
|
290
295
|
**认证与反风控:**
|
|
291
296
|
- Cookie 认证:支持环境变量和浏览器自动提取
|
|
292
297
|
- 完整 Cookie 转发:提取浏览器中所有 Twitter Cookie
|
|
293
|
-
- TLS 指纹伪装:`curl_cffi` Chrome
|
|
298
|
+
- TLS 指纹伪装:`curl_cffi` 动态匹配 Chrome 版本
|
|
294
299
|
- `x-client-transaction-id` 请求头生成
|
|
295
300
|
- 请求时序随机化(jitter)
|
|
301
|
+
- 写操作随机延迟(1.5–4 秒),降低频率风控
|
|
296
302
|
- 代理支持:`TWITTER_PROXY` 环境变量
|
|
297
303
|
|
|
298
304
|
### 安装
|
|
@@ -316,6 +322,8 @@ twitter favorites
|
|
|
316
322
|
# 搜索
|
|
317
323
|
twitter search "Claude Code"
|
|
318
324
|
twitter search "AI agent" -t Latest --max 50
|
|
325
|
+
twitter search "topic" -o results.json # 保存到文件
|
|
326
|
+
twitter search "trending" --filter # 启用排序筛选
|
|
319
327
|
|
|
320
328
|
# 推文详情
|
|
321
329
|
twitter tweet 1234567890
|
|
@@ -326,7 +334,9 @@ twitter list 1539453138322673664
|
|
|
326
334
|
# 用户
|
|
327
335
|
twitter user elonmusk
|
|
328
336
|
twitter user-posts elonmusk --max 20
|
|
337
|
+
twitter user-posts elonmusk -o tweets.json
|
|
329
338
|
twitter likes elonmusk --max 30
|
|
339
|
+
twitter likes elonmusk -o likes.json
|
|
330
340
|
twitter followers elonmusk
|
|
331
341
|
twitter following elonmusk
|
|
332
342
|
|
|
@@ -18,7 +18,7 @@ Use this skill when the user wants to read or interact with Twitter/X content fr
|
|
|
18
18
|
## Prerequisites
|
|
19
19
|
|
|
20
20
|
```bash
|
|
21
|
-
# Install (requires Python 3.
|
|
21
|
+
# Install (requires Python 3.8+)
|
|
22
22
|
uv tool install twitter-cli
|
|
23
23
|
# Or: pipx install twitter-cli
|
|
24
24
|
```
|
|
@@ -55,6 +55,8 @@ twitter favorites --filter # Apply ranking filter
|
|
|
55
55
|
twitter search "keyword"
|
|
56
56
|
twitter search "AI agent" -t Latest --max 50
|
|
57
57
|
twitter search "机器学习" --json
|
|
58
|
+
twitter search "topic" -o results.json # Save to file
|
|
59
|
+
twitter search "trending" --filter # Apply ranking filter
|
|
58
60
|
```
|
|
59
61
|
|
|
60
62
|
### Tweet Detail
|
|
@@ -75,7 +77,9 @@ twitter list 1539453138322673664 # Fetch tweets from a Twitter List
|
|
|
75
77
|
```bash
|
|
76
78
|
twitter user elonmusk # User profile
|
|
77
79
|
twitter user-posts elonmusk --max 20 # User's tweets
|
|
80
|
+
twitter user-posts elonmusk -o tweets.json # Save to file
|
|
78
81
|
twitter likes elonmusk --max 30 # User's likes
|
|
82
|
+
twitter likes elonmusk -o likes.json # Save to file
|
|
79
83
|
twitter followers elonmusk --max 50 # User's followers
|
|
80
84
|
twitter following elonmusk --max 50 # User's following
|
|
81
85
|
```
|
|
@@ -101,6 +105,8 @@ twitter feed --json > tweets.json
|
|
|
101
105
|
twitter feed --input tweets.json
|
|
102
106
|
twitter user-posts elonmusk --json | jq '.[0].text'
|
|
103
107
|
twitter search "keyword" --json | jq 'length'
|
|
108
|
+
twitter search "topic" -o results.json
|
|
109
|
+
twitter likes elonmusk -o likes.json
|
|
104
110
|
```
|
|
105
111
|
|
|
106
112
|
## Ranking Filter
|
|
@@ -149,6 +155,8 @@ twitter favorites --filter
|
|
|
149
155
|
|
|
150
156
|
## Safety Notes
|
|
151
157
|
|
|
158
|
+
- Write operations have built-in random delays (1.5–4s) to avoid rate limits.
|
|
159
|
+
- TLS fingerprint and User-Agent are automatically matched to the Chrome version used.
|
|
152
160
|
- Do not ask users to share raw cookie values in chat logs.
|
|
153
161
|
- Prefer local browser cookie extraction over manual secret copy/paste.
|
|
154
162
|
- If auth fails with 401/403, ask the user to re-login to `x.com`.
|
|
@@ -252,7 +252,7 @@ def extract_from_browser() -> Optional[Dict[str, str]]:
|
|
|
252
252
|
|
|
253
253
|
|
|
254
254
|
def get_cookies() -> Dict[str, str]:
|
|
255
|
-
"""Get Twitter cookies. Priority: env vars -> browser extraction
|
|
255
|
+
"""Get Twitter cookies. Priority: env vars -> cache file -> browser extraction.
|
|
256
256
|
|
|
257
257
|
Raises RuntimeError if no cookies found.
|
|
258
258
|
"""
|
|
@@ -263,9 +263,17 @@ def get_cookies() -> Dict[str, str]:
|
|
|
263
263
|
if cookies:
|
|
264
264
|
logger.info("Loaded cookies from environment variables")
|
|
265
265
|
|
|
266
|
-
# 2. Try
|
|
266
|
+
# 2. Try cached cookies (file cache with TTL)
|
|
267
|
+
if not cookies:
|
|
268
|
+
cookies = _load_cookie_cache()
|
|
269
|
+
if cookies:
|
|
270
|
+
logger.info("Loaded cookies from cache")
|
|
271
|
+
|
|
272
|
+
# 3. Try browser extraction (auto-detect)
|
|
267
273
|
if not cookies:
|
|
268
274
|
cookies = extract_from_browser()
|
|
275
|
+
if cookies:
|
|
276
|
+
_save_cookie_cache(cookies)
|
|
269
277
|
|
|
270
278
|
if not cookies:
|
|
271
279
|
raise RuntimeError(
|
|
@@ -275,7 +283,69 @@ def get_cookies() -> Dict[str, str]:
|
|
|
275
283
|
)
|
|
276
284
|
|
|
277
285
|
# Verify only for explicit auth failures; transient endpoint issues are tolerated.
|
|
278
|
-
|
|
286
|
+
try:
|
|
287
|
+
verify_cookies(cookies["auth_token"], cookies["ct0"], cookies.get("cookie_string"))
|
|
288
|
+
except RuntimeError:
|
|
289
|
+
# Auth failure — invalidate cache and re-extract from browser
|
|
290
|
+
logger.info("Cookie verification failed, invalidating cache and re-extracting")
|
|
291
|
+
invalidate_cookie_cache()
|
|
292
|
+
fresh_cookies = extract_from_browser()
|
|
293
|
+
if fresh_cookies:
|
|
294
|
+
_save_cookie_cache(fresh_cookies)
|
|
295
|
+
# Verify fresh cookies — if this also fails, let it raise
|
|
296
|
+
verify_cookies(fresh_cookies["auth_token"], fresh_cookies["ct0"], fresh_cookies.get("cookie_string"))
|
|
297
|
+
return fresh_cookies
|
|
298
|
+
raise
|
|
279
299
|
return cookies
|
|
280
300
|
|
|
281
301
|
|
|
302
|
+
# ── Cookie file cache ───────────────────────────────────────────────────
|
|
303
|
+
|
|
304
|
+
_CACHE_DIR = os.path.join(os.path.expanduser("~"), ".cache", "twitter-cli")
|
|
305
|
+
_CACHE_FILE = os.path.join(_CACHE_DIR, "cookies.json")
|
|
306
|
+
_CACHE_TTL_SECONDS = 24 * 3600 # 24 hours
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
def _load_cookie_cache():
|
|
310
|
+
# type: () -> Optional[Dict[str, str]]
|
|
311
|
+
"""Load cookies from file cache if within TTL."""
|
|
312
|
+
try:
|
|
313
|
+
if not os.path.exists(_CACHE_FILE):
|
|
314
|
+
return None
|
|
315
|
+
import time as _time
|
|
316
|
+
mtime = os.path.getmtime(_CACHE_FILE)
|
|
317
|
+
if _time.time() - mtime > _CACHE_TTL_SECONDS:
|
|
318
|
+
logger.debug("Cookie cache expired (>%ds)", _CACHE_TTL_SECONDS)
|
|
319
|
+
return None
|
|
320
|
+
with open(_CACHE_FILE, "r", encoding="utf-8") as f:
|
|
321
|
+
data = json.load(f)
|
|
322
|
+
if isinstance(data, dict) and "auth_token" in data and "ct0" in data:
|
|
323
|
+
return data
|
|
324
|
+
except Exception as exc:
|
|
325
|
+
logger.debug("Failed to load cookie cache: %s", exc)
|
|
326
|
+
return None
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
def _save_cookie_cache(cookies):
|
|
330
|
+
# type: (Dict[str, str]) -> None
|
|
331
|
+
"""Save cookies to file cache."""
|
|
332
|
+
try:
|
|
333
|
+
os.makedirs(_CACHE_DIR, exist_ok=True)
|
|
334
|
+
with open(_CACHE_FILE, "w", encoding="utf-8") as f:
|
|
335
|
+
json.dump(cookies, f, ensure_ascii=False)
|
|
336
|
+
# Restrict permissions — cookies are sensitive
|
|
337
|
+
os.chmod(_CACHE_FILE, 0o600)
|
|
338
|
+
logger.info("Saved cookies to cache (%s)", _CACHE_FILE)
|
|
339
|
+
except Exception as exc:
|
|
340
|
+
logger.debug("Failed to save cookie cache: %s", exc)
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
def invalidate_cookie_cache():
|
|
344
|
+
# type: () -> None
|
|
345
|
+
"""Delete the cookie cache file."""
|
|
346
|
+
try:
|
|
347
|
+
if os.path.exists(_CACHE_FILE):
|
|
348
|
+
os.remove(_CACHE_FILE)
|
|
349
|
+
logger.info("Cookie cache invalidated")
|
|
350
|
+
except Exception as exc:
|
|
351
|
+
logger.debug("Failed to invalidate cookie cache: %s", exc)
|
|
@@ -28,6 +28,8 @@ import sys
|
|
|
28
28
|
import time
|
|
29
29
|
from pathlib import Path
|
|
30
30
|
|
|
31
|
+
import json
|
|
32
|
+
|
|
31
33
|
import click
|
|
32
34
|
from rich.console import Console
|
|
33
35
|
|
|
@@ -43,7 +45,7 @@ from .formatter import (
|
|
|
43
45
|
print_user_profile,
|
|
44
46
|
print_user_table,
|
|
45
47
|
)
|
|
46
|
-
from .serialization import tweets_from_json, tweets_to_json, users_to_json
|
|
48
|
+
from .serialization import tweets_from_json, tweets_to_json, user_profile_to_dict, users_to_json
|
|
47
49
|
|
|
48
50
|
|
|
49
51
|
console = Console(stderr=True)
|
|
@@ -223,8 +225,9 @@ def favorites(max_count, as_json, output_file, do_filter):
|
|
|
223
225
|
|
|
224
226
|
@cli.command()
|
|
225
227
|
@click.argument("screen_name")
|
|
226
|
-
|
|
227
|
-
|
|
228
|
+
@click.option("--json", "as_json", is_flag=True, help="Output as JSON.")
|
|
229
|
+
def user(screen_name, as_json):
|
|
230
|
+
# type: (str, bool) -> None
|
|
228
231
|
"""View a user's profile. SCREEN_NAME is the @handle (without @)."""
|
|
229
232
|
screen_name = screen_name.lstrip("@")
|
|
230
233
|
config = load_config()
|
|
@@ -236,8 +239,11 @@ def user(screen_name):
|
|
|
236
239
|
console.print("[red]❌ %s[/red]" % exc)
|
|
237
240
|
sys.exit(1)
|
|
238
241
|
|
|
239
|
-
|
|
240
|
-
|
|
242
|
+
if as_json:
|
|
243
|
+
click.echo(json.dumps(user_profile_to_dict(profile), ensure_ascii=False, indent=2))
|
|
244
|
+
else:
|
|
245
|
+
console.print()
|
|
246
|
+
print_user_profile(profile, console)
|
|
241
247
|
|
|
242
248
|
|
|
243
249
|
@cli.command("user-posts")
|
|
@@ -486,7 +492,7 @@ def unlike(tweet_id):
|
|
|
486
492
|
|
|
487
493
|
@cli.command()
|
|
488
494
|
@click.argument("tweet_id")
|
|
489
|
-
def
|
|
495
|
+
def retweet(tweet_id):
|
|
490
496
|
# type: (str,) -> None
|
|
491
497
|
"""Retweet a tweet. TWEET_ID is the numeric tweet ID."""
|
|
492
498
|
_write_action("🔄", "Retweeting", "retweet", tweet_id)
|
|
@@ -494,7 +500,7 @@ def rt(tweet_id):
|
|
|
494
500
|
|
|
495
501
|
@cli.command()
|
|
496
502
|
@click.argument("tweet_id")
|
|
497
|
-
def
|
|
503
|
+
def unretweet(tweet_id):
|
|
498
504
|
# type: (str,) -> None
|
|
499
505
|
"""Undo a retweet. TWEET_ID is the numeric tweet ID."""
|
|
500
506
|
_write_action("🔄", "Undoing retweet", "unretweet", tweet_id)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|