twitter-cli 0.5.1__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.
Files changed (41) hide show
  1. {twitter_cli-0.5.1 → twitter_cli-0.6.0}/.github/workflows/publish-clawhub.yml +14 -6
  2. {twitter_cli-0.5.1 → twitter_cli-0.6.0}/PKG-INFO +33 -3
  3. {twitter_cli-0.5.1 → twitter_cli-0.6.0}/README.md +32 -2
  4. {twitter_cli-0.5.1 → twitter_cli-0.6.0}/SKILL.md +7 -1
  5. {twitter_cli-0.5.1 → twitter_cli-0.6.0}/pyproject.toml +1 -1
  6. {twitter_cli-0.5.1 → twitter_cli-0.6.0}/tests/test_auth.py +103 -0
  7. {twitter_cli-0.5.1 → twitter_cli-0.6.0}/twitter_cli/auth.py +191 -33
  8. {twitter_cli-0.5.1 → twitter_cli-0.6.0}/twitter_cli/cli.py +26 -1
  9. {twitter_cli-0.5.1 → twitter_cli-0.6.0}/twitter_cli/client.py +3 -1
  10. {twitter_cli-0.5.1 → twitter_cli-0.6.0}/uv.lock +1 -1
  11. {twitter_cli-0.5.1 → twitter_cli-0.6.0}/.github/workflows/ci.yml +0 -0
  12. {twitter_cli-0.5.1 → twitter_cli-0.6.0}/.github/workflows/publish.yml +0 -0
  13. {twitter_cli-0.5.1 → twitter_cli-0.6.0}/.gitignore +0 -0
  14. {twitter_cli-0.5.1 → twitter_cli-0.6.0}/LICENSE +0 -0
  15. {twitter_cli-0.5.1 → twitter_cli-0.6.0}/SCHEMA.md +0 -0
  16. {twitter_cli-0.5.1 → twitter_cli-0.6.0}/config.yaml +0 -0
  17. {twitter_cli-0.5.1 → twitter_cli-0.6.0}/tests/conftest.py +0 -0
  18. {twitter_cli-0.5.1 → twitter_cli-0.6.0}/tests/fixtures/followers_page.json +0 -0
  19. {twitter_cli-0.5.1 → twitter_cli-0.6.0}/tests/fixtures/home_timeline.json +0 -0
  20. {twitter_cli-0.5.1 → twitter_cli-0.6.0}/tests/fixtures/list_timeline.json +0 -0
  21. {twitter_cli-0.5.1 → twitter_cli-0.6.0}/tests/fixtures/search_timeline.json +0 -0
  22. {twitter_cli-0.5.1 → twitter_cli-0.6.0}/tests/fixtures/tweet_detail.json +0 -0
  23. {twitter_cli-0.5.1 → twitter_cli-0.6.0}/tests/test_cli.py +0 -0
  24. {twitter_cli-0.5.1 → twitter_cli-0.6.0}/tests/test_client.py +0 -0
  25. {twitter_cli-0.5.1 → twitter_cli-0.6.0}/tests/test_config.py +0 -0
  26. {twitter_cli-0.5.1 → twitter_cli-0.6.0}/tests/test_config_normalization.py +0 -0
  27. {twitter_cli-0.5.1 → twitter_cli-0.6.0}/tests/test_filter.py +0 -0
  28. {twitter_cli-0.5.1 → twitter_cli-0.6.0}/tests/test_parser_fixtures.py +0 -0
  29. {twitter_cli-0.5.1 → twitter_cli-0.6.0}/tests/test_serialization.py +0 -0
  30. {twitter_cli-0.5.1 → twitter_cli-0.6.0}/tests/test_smoke.py +0 -0
  31. {twitter_cli-0.5.1 → twitter_cli-0.6.0}/twitter_cli/__init__.py +0 -0
  32. {twitter_cli-0.5.1 → twitter_cli-0.6.0}/twitter_cli/config.py +0 -0
  33. {twitter_cli-0.5.1 → twitter_cli-0.6.0}/twitter_cli/constants.py +0 -0
  34. {twitter_cli-0.5.1 → twitter_cli-0.6.0}/twitter_cli/exceptions.py +0 -0
  35. {twitter_cli-0.5.1 → twitter_cli-0.6.0}/twitter_cli/filter.py +0 -0
  36. {twitter_cli-0.5.1 → twitter_cli-0.6.0}/twitter_cli/formatter.py +0 -0
  37. {twitter_cli-0.5.1 → twitter_cli-0.6.0}/twitter_cli/graphql.py +0 -0
  38. {twitter_cli-0.5.1 → twitter_cli-0.6.0}/twitter_cli/models.py +0 -0
  39. {twitter_cli-0.5.1 → twitter_cli-0.6.0}/twitter_cli/output.py +0 -0
  40. {twitter_cli-0.5.1 → twitter_cli-0.6.0}/twitter_cli/parser.py +0 -0
  41. {twitter_cli-0.5.1 → twitter_cli-0.6.0}/twitter_cli/serialization.py +0 -0
@@ -51,11 +51,14 @@ jobs:
51
51
  fi
52
52
 
53
53
  clawhub --no-input login --token "${CLAWHUB_TOKEN}" --no-browser
54
+ export VERSION
54
55
 
55
56
  # Workaround: clawhub@0.7.0 publish doesn't send acceptLicenseTerms,
56
57
  # which the server now requires. Use a Node.js script to publish with
57
58
  # the corrected payload.
58
- node - <<'PUBLISH_SCRIPT'
59
+ # Note: NODE_TLS_REJECT_UNAUTHORIZED=0 is needed because api.clawhub.io
60
+ # has an expired SSL certificate. Remove once ClawHub renews their cert.
61
+ NODE_TLS_REJECT_UNAUTHORIZED=0 node - <<'PUBLISH_SCRIPT'
59
62
  const { resolve } = require("path");
60
63
  const { readFileSync, statSync, readdirSync } = require("fs");
61
64
  const folder = resolve(".");
@@ -105,15 +108,20 @@ jobs:
105
108
  } catch {}
106
109
  if (!token) { console.error("No token found"); process.exit(1); }
107
110
 
108
- const registry = "https://api.clawhub.io";
111
+ const registry = "https://clawhub.ai";
109
112
  fetch(registry + "/api/v1/skills", {
110
113
  method: "POST",
111
114
  headers: { Authorization: "Bearer " + token },
112
115
  body: form,
113
- }).then(async r => {
116
+ }).then(async (r) => {
114
117
  const text = await r.text();
115
- if (!r.ok) { console.error("Publish failed:", r.status, text); process.exit(1); }
118
+ if (!r.ok) {
119
+ console.error("Publish failed:", r.status, text);
120
+ process.exit(1);
121
+ }
116
122
  console.log("✔ Published", slug + "@" + version);
117
- }).catch(e => { console.error(e); process.exit(1); });
123
+ }).catch((e) => {
124
+ console.error(e);
125
+ process.exit(1);
126
+ });
118
127
  PUBLISH_SCRIPT
119
-
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: twitter-cli
3
- Version: 0.5.1
3
+ Version: 0.6.0
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
@@ -91,6 +91,15 @@ uv tool install twitter-cli
91
91
  pipx install twitter-cli
92
92
  ```
93
93
 
94
+ Upgrade to the latest version:
95
+
96
+ ```bash
97
+ uv tool upgrade twitter-cli
98
+ # Or: pipx upgrade twitter-cli
99
+ ```
100
+
101
+ > **Tip:** Upgrade regularly to avoid unexpected errors from outdated API handling.
102
+
94
103
  Install from source:
95
104
 
96
105
  ```bash
@@ -142,7 +151,7 @@ twitter list 1539453138322673664
142
151
  twitter user elonmusk
143
152
  twitter user-posts elonmusk --max 20
144
153
  twitter user-posts elonmusk -o tweets.json
145
- twitter likes elonmusk --max 30
154
+ twitter likes elonmusk --max 30 # ⚠️ own likes only (private since Jun 2024)
146
155
  twitter likes elonmusk -o likes.json
147
156
  twitter followers elonmusk --max 50
148
157
  twitter following elonmusk --max 50
@@ -171,6 +180,12 @@ twitter-cli uses this auth priority:
171
180
 
172
181
  Browser extraction is recommended — it forwards ALL Twitter cookies (not just `auth_token` + `ct0`) and aligns request headers with your local runtime, which is closer to normal browser traffic than minimal cookie auth.
173
182
 
183
+ **Chrome multi-profile**: All Chrome profiles are scanned automatically. To specify a profile:
184
+
185
+ ```bash
186
+ TWITTER_CHROME_PROFILE="Profile 2" twitter feed
187
+ ```
188
+
174
189
  After loading cookies, the CLI performs lightweight verification. Commands that require account access fail fast on clear auth errors (`401/403`).
175
190
 
176
191
  ### Proxy Support
@@ -365,6 +380,15 @@ After installation, OpenClaw can call `twitter-cli` commands directly.
365
380
  uv tool install twitter-cli
366
381
  ```
367
382
 
383
+ 升级到最新版本:
384
+
385
+ ```bash
386
+ uv tool upgrade twitter-cli
387
+ # 或:pipx upgrade twitter-cli
388
+ ```
389
+
390
+ > **提示:** 建议定期升级,避免因版本过旧导致的 API 调用异常。
391
+
368
392
  ### 使用指南
369
393
 
370
394
  ```bash
@@ -392,7 +416,7 @@ twitter list 1539453138322673664
392
416
  twitter user elonmusk
393
417
  twitter user-posts elonmusk --max 20
394
418
  twitter user-posts elonmusk -o tweets.json
395
- twitter likes elonmusk --max 30
419
+ twitter likes elonmusk --max 30 # ⚠️ 仅可查看自己的点赞(2024年6月起平台已私密化)
396
420
  twitter likes elonmusk -o likes.json
397
421
  twitter followers elonmusk
398
422
  twitter following elonmusk
@@ -421,6 +445,12 @@ twitter follow elonmusk --json
421
445
 
422
446
  推荐使用浏览器提取方式,会转发所有 Twitter Cookie,并按本机运行环境生成语言和平台请求头;它比仅发送 `auth_token` + `ct0` 更接近普通浏览器流量,但不等于完整浏览器自动化。
423
447
 
448
+ **Chrome 多 Profile 支持**:会自动遍历所有 Chrome profile。也可以通过环境变量指定:
449
+
450
+ ```bash
451
+ TWITTER_CHROME_PROFILE="Profile 2" twitter feed
452
+ ```
453
+
424
454
  ### 代理支持
425
455
 
426
456
  设置 `TWITTER_PROXY` 环境变量即可:
@@ -59,6 +59,15 @@ uv tool install twitter-cli
59
59
  pipx install twitter-cli
60
60
  ```
61
61
 
62
+ Upgrade to the latest version:
63
+
64
+ ```bash
65
+ uv tool upgrade twitter-cli
66
+ # Or: pipx upgrade twitter-cli
67
+ ```
68
+
69
+ > **Tip:** Upgrade regularly to avoid unexpected errors from outdated API handling.
70
+
62
71
  Install from source:
63
72
 
64
73
  ```bash
@@ -110,7 +119,7 @@ twitter list 1539453138322673664
110
119
  twitter user elonmusk
111
120
  twitter user-posts elonmusk --max 20
112
121
  twitter user-posts elonmusk -o tweets.json
113
- twitter likes elonmusk --max 30
122
+ twitter likes elonmusk --max 30 # ⚠️ own likes only (private since Jun 2024)
114
123
  twitter likes elonmusk -o likes.json
115
124
  twitter followers elonmusk --max 50
116
125
  twitter following elonmusk --max 50
@@ -139,6 +148,12 @@ twitter-cli uses this auth priority:
139
148
 
140
149
  Browser extraction is recommended — it forwards ALL Twitter cookies (not just `auth_token` + `ct0`) and aligns request headers with your local runtime, which is closer to normal browser traffic than minimal cookie auth.
141
150
 
151
+ **Chrome multi-profile**: All Chrome profiles are scanned automatically. To specify a profile:
152
+
153
+ ```bash
154
+ TWITTER_CHROME_PROFILE="Profile 2" twitter feed
155
+ ```
156
+
142
157
  After loading cookies, the CLI performs lightweight verification. Commands that require account access fail fast on clear auth errors (`401/403`).
143
158
 
144
159
  ### Proxy Support
@@ -333,6 +348,15 @@ After installation, OpenClaw can call `twitter-cli` commands directly.
333
348
  uv tool install twitter-cli
334
349
  ```
335
350
 
351
+ 升级到最新版本:
352
+
353
+ ```bash
354
+ uv tool upgrade twitter-cli
355
+ # 或:pipx upgrade twitter-cli
356
+ ```
357
+
358
+ > **提示:** 建议定期升级,避免因版本过旧导致的 API 调用异常。
359
+
336
360
  ### 使用指南
337
361
 
338
362
  ```bash
@@ -360,7 +384,7 @@ twitter list 1539453138322673664
360
384
  twitter user elonmusk
361
385
  twitter user-posts elonmusk --max 20
362
386
  twitter user-posts elonmusk -o tweets.json
363
- twitter likes elonmusk --max 30
387
+ twitter likes elonmusk --max 30 # ⚠️ 仅可查看自己的点赞(2024年6月起平台已私密化)
364
388
  twitter likes elonmusk -o likes.json
365
389
  twitter followers elonmusk
366
390
  twitter following elonmusk
@@ -389,6 +413,12 @@ twitter follow elonmusk --json
389
413
 
390
414
  推荐使用浏览器提取方式,会转发所有 Twitter Cookie,并按本机运行环境生成语言和平台请求头;它比仅发送 `auth_token` + `ct0` 更接近普通浏览器流量,但不等于完整浏览器自动化。
391
415
 
416
+ **Chrome 多 Profile 支持**:会自动遍历所有 Chrome profile。也可以通过环境变量指定:
417
+
418
+ ```bash
419
+ TWITTER_CHROME_PROFILE="Profile 2" twitter feed
420
+ ```
421
+
392
422
  ### 代理支持
393
423
 
394
424
  设置 `TWITTER_PROXY` 环境变量即可:
@@ -22,6 +22,10 @@ tags:
22
22
  # Install (requires Python 3.8+)
23
23
  uv tool install twitter-cli
24
24
  # Or: pipx install twitter-cli
25
+
26
+ # Upgrade to latest (recommended to avoid API errors)
27
+ uv tool upgrade twitter-cli
28
+ # Or: pipx upgrade twitter-cli
25
29
  ```
26
30
 
27
31
  ## Authentication
@@ -44,6 +48,7 @@ If `AUTH_NEEDED`, proceed to guide the user:
44
48
  **Method A: Browser cookie extraction (recommended)**
45
49
 
46
50
  Ensure user is logged into x.com in one of: Arc, Chrome, Edge, Firefox, Brave. twitter-cli auto-extracts cookies.
51
+ All Chrome profiles are scanned automatically. To specify a profile: `TWITTER_CHROME_PROFILE="Profile 2" twitter feed`.
47
52
 
48
53
  ```bash
49
54
  twitter whoami
@@ -145,7 +150,7 @@ twitter tweet 1234567890 # Tweet detail + replies
145
150
  twitter tweet https://x.com/user/status/12345 # Accepts URL
146
151
  twitter list 1539453138322673664 # List timeline
147
152
  twitter user-posts elonmusk --max 20 # User's tweets
148
- twitter likes elonmusk --max 30 # User's likes
153
+ twitter likes elonmusk --max 30 # User's likes (own only, see note)
149
154
  twitter followers elonmusk --max 50 # Followers
150
155
  twitter following elonmusk --max 50 # Following
151
156
  ```
@@ -282,6 +287,7 @@ twitter bookmarks --filter
282
287
  - **No notifications** — can't read notifications
283
288
  - **No polls** — can't create polls
284
289
  - **Single account** — one set of credentials at a time
290
+ - **Likes are private** — Twitter/X made all likes private since June 2024. `twitter likes` only works for your own account
285
291
 
286
292
  ## Safety Notes
287
293
 
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "twitter-cli"
7
- version = "0.5.1"
7
+ version = "0.6.0"
8
8
  description = "A CLI for Twitter/X — feed, bookmarks, and user timeline in terminal"
9
9
  readme = "README.md"
10
10
  license = "Apache-2.0"
@@ -1,6 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import json
4
+ import os
4
5
  import sys
5
6
  from types import SimpleNamespace
6
7
 
@@ -187,3 +188,105 @@ def test_verify_cookies_logs_attempt_summary_on_non_auth_failures(monkeypatch, c
187
188
  assert result == {}
188
189
  assert "verify_credentials.json=404" in caplog.text
189
190
  assert "settings.json=Exception" in caplog.text
191
+
192
+
193
+ def test_iter_chrome_cookie_files_default_first(monkeypatch, tmp_path) -> None:
194
+ """Default profile should be yielded first, then Profile N sorted."""
195
+ # Create the correct platform-specific directory structure
196
+ if sys.platform == "darwin":
197
+ chrome_dir = tmp_path / "Library" / "Application Support" / "Google" / "Chrome"
198
+ elif sys.platform == "win32":
199
+ chrome_dir = tmp_path / "Google" / "Chrome" / "User Data"
200
+ else:
201
+ chrome_dir = tmp_path / ".config" / "Google" / "Chrome"
202
+
203
+ (chrome_dir / "Default").mkdir(parents=True)
204
+ (chrome_dir / "Default" / "Cookies").touch()
205
+ (chrome_dir / "Profile 2").mkdir()
206
+ (chrome_dir / "Profile 2" / "Cookies").touch()
207
+ (chrome_dir / "Profile 1").mkdir()
208
+ (chrome_dir / "Profile 1" / "Cookies").touch()
209
+
210
+ monkeypatch.delenv("TWITTER_CHROME_PROFILE", raising=False)
211
+ monkeypatch.setenv("HOME", str(tmp_path))
212
+ if sys.platform == "win32":
213
+ monkeypatch.setenv("LOCALAPPDATA", str(tmp_path))
214
+
215
+ paths = auth._iter_chrome_cookie_files("chrome")
216
+
217
+ basenames = [os.path.basename(os.path.dirname(p)) for p in paths]
218
+ assert basenames[0] == "Default"
219
+ assert "Profile 1" in basenames
220
+ assert "Profile 2" in basenames
221
+ # Profile 1 should come before Profile 2
222
+ assert basenames.index("Profile 1") < basenames.index("Profile 2")
223
+
224
+
225
+ def test_iter_chrome_cookie_files_env_override(monkeypatch, tmp_path) -> None:
226
+ """TWITTER_CHROME_PROFILE should restrict to that single profile."""
227
+ if sys.platform == "darwin":
228
+ chrome_dir = tmp_path / "Library" / "Application Support" / "Google" / "Chrome"
229
+ else:
230
+ chrome_dir = tmp_path / ".config" / "Google" / "Chrome"
231
+
232
+ (chrome_dir / "Default").mkdir(parents=True)
233
+ (chrome_dir / "Default" / "Cookies").touch()
234
+ (chrome_dir / "Profile 5").mkdir()
235
+ (chrome_dir / "Profile 5" / "Cookies").touch()
236
+
237
+ monkeypatch.setenv("HOME", str(tmp_path))
238
+ monkeypatch.setenv("TWITTER_CHROME_PROFILE", "Profile 5")
239
+
240
+ paths = auth._iter_chrome_cookie_files("chrome")
241
+
242
+ assert len(paths) == 1
243
+ assert "Profile 5" in paths[0]
244
+
245
+
246
+ def test_extract_in_process_tries_multiple_profiles(monkeypatch, tmp_path) -> None:
247
+ """When Default has no Twitter cookies but Profile 1 does, it should find them."""
248
+
249
+ class Cookie:
250
+ def __init__(self, domain: str, name: str, value: str) -> None:
251
+ self.domain = domain
252
+ self.name = name
253
+ self.value = value
254
+
255
+ default_cookies_path = str(tmp_path / "Default" / "Cookies")
256
+ profile1_cookies_path = str(tmp_path / "Profile 1" / "Cookies")
257
+ os.makedirs(os.path.dirname(default_cookies_path), exist_ok=True)
258
+ os.makedirs(os.path.dirname(profile1_cookies_path), exist_ok=True)
259
+ open(default_cookies_path, "w").close()
260
+ open(profile1_cookies_path, "w").close()
261
+
262
+ # Mock _iter_chrome_cookie_files to return our tmp paths
263
+ def mock_iter(browser_name):
264
+ if browser_name == "arc":
265
+ return [default_cookies_path, profile1_cookies_path]
266
+ return []
267
+
268
+ monkeypatch.setattr(auth, "_iter_chrome_cookie_files", mock_iter)
269
+
270
+ # Arc: Default returns empty jar, Profile 1 returns valid cookies
271
+ def mock_arc(cookie_file=None):
272
+ if cookie_file == profile1_cookies_path:
273
+ return [
274
+ Cookie(".x.com", "auth_token", "tok123"),
275
+ Cookie(".x.com", "ct0", "csrf456"),
276
+ ]
277
+ return [] # Default — no cookies
278
+
279
+ fake_module = SimpleNamespace(
280
+ arc=mock_arc,
281
+ chrome=lambda cookie_file=None: [],
282
+ edge=lambda cookie_file=None: [],
283
+ firefox=lambda: [],
284
+ brave=lambda cookie_file=None: [],
285
+ )
286
+ monkeypatch.setitem(sys.modules, "browser_cookie3", fake_module)
287
+
288
+ cookies = auth._extract_in_process()
289
+
290
+ assert cookies is not None
291
+ assert cookies["auth_token"] == "tok123"
292
+ assert cookies["ct0"] == "csrf456"
@@ -10,12 +10,13 @@ Supports:
10
10
 
11
11
  from __future__ import annotations
12
12
 
13
+ import glob
13
14
  import json
14
15
  import logging
15
16
  import os
16
17
  import subprocess
17
18
  import sys
18
- from typing import Any, Dict, Optional, Tuple
19
+ from typing import Any, Dict, List, Optional, Tuple
19
20
 
20
21
  from .constants import BEARER_TOKEN, get_user_agent
21
22
 
@@ -141,12 +142,69 @@ def _extract_cookies_from_jar(jar: Any, source: str = "unknown") -> Optional[Dic
141
142
  return None
142
143
 
143
144
 
145
+ # Base directories for Chromium-based browsers, keyed by browser name.
146
+ # Each entry maps to the directory under the platform-specific app data root.
147
+ _CHROMIUM_BASE_DIRS: Dict[str, str] = {
148
+ "chrome": os.path.join("Google", "Chrome"),
149
+ "arc": os.path.join("Arc", "User Data"),
150
+ "edge": os.path.join("Microsoft Edge"),
151
+ "brave": os.path.join("BraveSoftware", "Brave-Browser"),
152
+ }
153
+
154
+
155
+ def _iter_chrome_cookie_files(browser_name: str) -> List[str]:
156
+ """Return cookie file paths for all Chrome profiles.
157
+
158
+ If TWITTER_CHROME_PROFILE is set, only that profile is returned.
159
+ Otherwise yields Default first, then Profile 1, Profile 2, ... sorted.
160
+ """
161
+ base_dir = _CHROMIUM_BASE_DIRS.get(browser_name)
162
+ if base_dir is None:
163
+ return []
164
+
165
+ if sys.platform == "darwin":
166
+ root = os.path.join(os.path.expanduser("~"), "Library", "Application Support", base_dir)
167
+ elif sys.platform == "win32":
168
+ root = os.path.join(os.environ.get("LOCALAPPDATA", ""), base_dir, "User Data")
169
+ else:
170
+ root = os.path.join(os.path.expanduser("~"), ".config", base_dir)
171
+
172
+ if not os.path.isdir(root):
173
+ return []
174
+
175
+ # If user explicitly specifies a profile, only use that one
176
+ env_profile = os.environ.get("TWITTER_CHROME_PROFILE", "").strip()
177
+ if env_profile:
178
+ cookie_path = os.path.join(root, env_profile, "Cookies")
179
+ if os.path.exists(cookie_path):
180
+ logger.debug("Using specified Chrome profile: %s", env_profile)
181
+ return [cookie_path]
182
+ logger.warning("TWITTER_CHROME_PROFILE='%s' not found at %s", env_profile, cookie_path)
183
+ return []
184
+
185
+ # Auto-discover: Default first, then Profile N sorted
186
+ paths: List[str] = []
187
+ default_cookies = os.path.join(root, "Default", "Cookies")
188
+ if os.path.exists(default_cookies):
189
+ paths.append(default_cookies)
190
+
191
+ profile_dirs = sorted(glob.glob(os.path.join(root, "Profile *")))
192
+ for profile_dir in profile_dirs:
193
+ cookie_file = os.path.join(profile_dir, "Cookies")
194
+ if os.path.exists(cookie_file):
195
+ paths.append(cookie_file)
196
+
197
+ return paths
198
+
199
+
144
200
  def _extract_in_process() -> Optional[Dict[str, str]]:
145
201
  """Extract cookies in the main process (required on macOS for Keychain access).
146
202
 
147
203
  On macOS, Chrome encrypts cookies using a key stored in the system Keychain.
148
204
  Child processes do NOT inherit the parent's Keychain authorization, so
149
205
  browser_cookie3 must run in the main process to decrypt cookies.
206
+
207
+ For Chromium-based browsers, iterates all profiles to find Twitter cookies.
150
208
  """
151
209
  try:
152
210
  import browser_cookie3
@@ -164,17 +222,51 @@ def _extract_in_process() -> Optional[Dict[str, str]]:
164
222
  attempts = []
165
223
 
166
224
  for name, fn in browsers:
167
- try:
168
- jar = fn()
169
- except Exception as e:
170
- logger.debug("%s in-process extraction failed: %s", name, e)
171
- attempts.append("%s=%s" % (name, type(e).__name__))
172
- continue
173
- cookies = _extract_cookies_from_jar(jar, source="%s(in-process)" % name)
174
- if cookies:
175
- logger.info("Found cookies in %s (in-process)", name)
176
- return cookies
177
- attempts.append("%s=no-cookies" % name)
225
+ if name in _CHROMIUM_BASE_DIRS:
226
+ # Chromium-based: iterate all profiles
227
+ cookie_files = _iter_chrome_cookie_files(name)
228
+ if not cookie_files:
229
+ # No profile dirs found — try the default (no cookie_file arg)
230
+ try:
231
+ jar = fn()
232
+ except Exception as e:
233
+ logger.debug("%s in-process extraction failed: %s", name, e)
234
+ attempts.append("%s=%s" % (name, type(e).__name__))
235
+ continue
236
+ cookies = _extract_cookies_from_jar(jar, source="%s(in-process)" % name)
237
+ if cookies:
238
+ logger.info("Found cookies in %s (in-process, default)", name)
239
+ return cookies
240
+ attempts.append("%s=no-cookies" % name)
241
+ continue
242
+
243
+ for cookie_file in cookie_files:
244
+ profile_name = os.path.basename(os.path.dirname(cookie_file))
245
+ try:
246
+ jar = fn(cookie_file=cookie_file)
247
+ except Exception as e:
248
+ logger.debug("%s[%s] in-process extraction failed: %s", name, profile_name, e)
249
+ attempts.append("%s[%s]=%s" % (name, profile_name, type(e).__name__))
250
+ continue
251
+ cookies = _extract_cookies_from_jar(jar, source="%s[%s](in-process)" % (name, profile_name))
252
+ if cookies:
253
+ logger.info("Found cookies in %s profile '%s' (in-process)", name, profile_name)
254
+ return cookies
255
+ attempts.append("%s[%s]=no-cookies" % (name, profile_name))
256
+ else:
257
+ # Non-Chromium (Firefox): use default behavior
258
+ try:
259
+ jar = fn()
260
+ except Exception as e:
261
+ logger.debug("%s in-process extraction failed: %s", name, e)
262
+ attempts.append("%s=%s" % (name, type(e).__name__))
263
+ continue
264
+ cookies = _extract_cookies_from_jar(jar, source="%s(in-process)" % name)
265
+ if cookies:
266
+ logger.info("Found cookies in %s (in-process)", name)
267
+ return cookies
268
+ attempts.append("%s=no-cookies" % name)
269
+
178
270
  if attempts:
179
271
  logger.debug("In-process extraction attempts: %s", ", ".join(attempts))
180
272
  return None
@@ -183,28 +275,47 @@ def _extract_in_process() -> Optional[Dict[str, str]]:
183
275
  def _extract_via_subprocess() -> Optional[Dict[str, str]]:
184
276
  """Extract cookies via subprocess (fallback if in-process fails, e.g. SQLite lock)."""
185
277
  extract_script = '''
186
- import json, sys
278
+ import glob, json, os, sys
187
279
  try:
188
280
  import browser_cookie3
189
281
  except ImportError:
190
282
  print(json.dumps({"error": "browser-cookie3 not installed"}))
191
283
  sys.exit(1)
192
284
 
193
- browsers = [
194
- ("arc", browser_cookie3.arc),
195
- ("chrome", browser_cookie3.chrome),
196
- ("edge", browser_cookie3.edge),
197
- ("firefox", browser_cookie3.firefox),
198
- ("brave", browser_cookie3.brave),
199
- ]
200
- attempts = []
201
-
202
- for name, fn in browsers:
203
- try:
204
- jar = fn()
205
- except Exception as exc:
206
- attempts.append(f"{name}={type(exc).__name__}")
207
- continue
285
+ CHROMIUM_BASE_DIRS = {
286
+ "chrome": os.path.join("Google", "Chrome"),
287
+ "arc": os.path.join("Arc", "User Data"),
288
+ "edge": os.path.join("Microsoft Edge"),
289
+ "brave": os.path.join("BraveSoftware", "Brave-Browser"),
290
+ }
291
+
292
+ def iter_cookie_files(browser_name):
293
+ base_dir = CHROMIUM_BASE_DIRS.get(browser_name)
294
+ if base_dir is None:
295
+ return []
296
+ if sys.platform == "darwin":
297
+ root = os.path.join(os.path.expanduser("~"), "Library", "Application Support", base_dir)
298
+ elif sys.platform == "win32":
299
+ root = os.path.join(os.environ.get("LOCALAPPDATA", ""), base_dir, "User Data")
300
+ else:
301
+ root = os.path.join(os.path.expanduser("~"), ".config", base_dir)
302
+ if not os.path.isdir(root):
303
+ return []
304
+ env_profile = os.environ.get("TWITTER_CHROME_PROFILE", "").strip()
305
+ if env_profile:
306
+ p = os.path.join(root, env_profile, "Cookies")
307
+ return [p] if os.path.exists(p) else []
308
+ paths = []
309
+ d = os.path.join(root, "Default", "Cookies")
310
+ if os.path.exists(d):
311
+ paths.append(d)
312
+ for pd in sorted(glob.glob(os.path.join(root, "Profile *"))):
313
+ cf = os.path.join(pd, "Cookies")
314
+ if os.path.exists(cf):
315
+ paths.append(cf)
316
+ return paths
317
+
318
+ def extract_from_jar(jar, name, profile=""):
208
319
  result = {}
209
320
  all_cookies = {}
210
321
  for cookie in jar:
@@ -218,12 +329,59 @@ for name, fn in browsers:
218
329
  all_cookies[cookie.name] = cookie.value
219
330
  if "auth_token" in result and "ct0" in result:
220
331
  result["browser"] = name
332
+ if profile:
333
+ result["profile"] = profile
221
334
  result["all_cookies"] = all_cookies
222
- print(json.dumps(result))
223
- sys.exit(0)
224
- attempts.append(
225
- f"{name}=no-cookies(auth_token={'auth_token' in result},ct0={'ct0' in result})"
226
- )
335
+ return result
336
+ return None
337
+
338
+ browsers = [
339
+ ("arc", browser_cookie3.arc),
340
+ ("chrome", browser_cookie3.chrome),
341
+ ("edge", browser_cookie3.edge),
342
+ ("firefox", browser_cookie3.firefox),
343
+ ("brave", browser_cookie3.brave),
344
+ ]
345
+ attempts = []
346
+
347
+ for name, fn in browsers:
348
+ if name in CHROMIUM_BASE_DIRS:
349
+ cookie_files = iter_cookie_files(name)
350
+ if not cookie_files:
351
+ try:
352
+ jar = fn()
353
+ except Exception as exc:
354
+ attempts.append(f"{name}={type(exc).__name__}")
355
+ continue
356
+ r = extract_from_jar(jar, name)
357
+ if r:
358
+ print(json.dumps(r))
359
+ sys.exit(0)
360
+ attempts.append(f"{name}=no-cookies")
361
+ continue
362
+ for cf in cookie_files:
363
+ pname = os.path.basename(os.path.dirname(cf))
364
+ try:
365
+ jar = fn(cookie_file=cf)
366
+ except Exception as exc:
367
+ attempts.append(f"{name}[{pname}]={type(exc).__name__}")
368
+ continue
369
+ r = extract_from_jar(jar, name, pname)
370
+ if r:
371
+ print(json.dumps(r))
372
+ sys.exit(0)
373
+ attempts.append(f"{name}[{pname}]=no-cookies")
374
+ else:
375
+ try:
376
+ jar = fn()
377
+ except Exception as exc:
378
+ attempts.append(f"{name}={type(exc).__name__}")
379
+ continue
380
+ r = extract_from_jar(jar, name)
381
+ if r:
382
+ print(json.dumps(r))
383
+ sys.exit(0)
384
+ attempts.append(f"{name}=no-cookies")
227
385
 
228
386
  print(json.dumps({
229
387
  "error": "No Twitter cookies found in any browser. Make sure you are logged into x.com.",
@@ -77,6 +77,7 @@ StructuredMode = Optional[str]
77
77
  WritePayload = Dict[str, Any]
78
78
  WriteOperation = Callable[[TwitterClient], WritePayload]
79
79
 
80
+ logger = logging.getLogger(__name__)
80
81
  console = Console(stderr=True)
81
82
  FEED_TYPES = ["for-you", "following"]
82
83
  SEARCH_PRODUCTS = ["Top", "Latest", "Photos", "Videos"]
@@ -539,7 +540,11 @@ def search(ctx, query, product, max_count, as_json, as_yaml, output_file, do_fil
539
540
  @click.pass_context
540
541
  def likes(ctx, screen_name, max_count, as_json, as_yaml, output_file, do_filter):
541
542
  # type: (Any, str, int, bool, bool, Optional[str], bool) -> None
542
- """Show tweets liked by a user. SCREEN_NAME is the @handle (without @)."""
543
+ """Show tweets liked by a user. SCREEN_NAME is the @handle (without @).
544
+
545
+ NOTE: Twitter/X made all likes private since June 2024. You can only view
546
+ your own likes. Querying another user's likes will return empty results.
547
+ """
543
548
  screen_name = screen_name.lstrip("@")
544
549
  compact = ctx.obj.get("compact", False)
545
550
  config = load_config()
@@ -549,6 +554,26 @@ def likes(ctx, screen_name, max_count, as_json, as_yaml, output_file, do_filter)
549
554
  if rich_output:
550
555
  console.print("👤 Fetching @%s's profile..." % screen_name)
551
556
  profile = client.fetch_user(screen_name)
557
+
558
+ # Warn if querying another user's likes (Twitter made likes private since June 2024)
559
+ try:
560
+ me = client.fetch_me()
561
+ if me.screen_name.lower() != screen_name.lower():
562
+ if rich_output:
563
+ console.print(
564
+ "\n[yellow]⚠️ Twitter/X made all likes private since June 2024. "
565
+ "You can only view your own likes. "
566
+ "Querying @%s's likes will likely return empty results.[/yellow]\n" % screen_name
567
+ )
568
+ else:
569
+ logger.warning(
570
+ "Twitter/X made likes private (June 2024). "
571
+ "Only your own likes are visible. @%s's likes will likely be empty.",
572
+ screen_name,
573
+ )
574
+ except Exception:
575
+ pass # Don't block the command if whoami fails
576
+
552
577
  _fetch_and_display(
553
578
  lambda count: client.fetch_user_likes(profile.id, count),
554
579
  "@%s likes" % screen_name, "❤️", max_count, as_json, as_yaml, output_file, do_filter, config,
@@ -76,7 +76,9 @@ def _best_chrome_target():
76
76
  try:
77
77
  from curl_cffi.requests import BrowserType
78
78
  available = {e.value for e in BrowserType}
79
- except Exception:
79
+ except ImportError:
80
+ # curl_cffi not installed or BrowserType not available
81
+ logger.debug("curl_cffi.BrowserType not available, using fallback targets")
80
82
  available = set()
81
83
 
82
84
  # Preference order: exact chrome versions, then suffixed variants
@@ -1010,7 +1010,7 @@ wheels = [
1010
1010
 
1011
1011
  [[package]]
1012
1012
  name = "twitter-cli"
1013
- version = "0.5.0"
1013
+ version = "0.5.1"
1014
1014
  source = { editable = "." }
1015
1015
  dependencies = [
1016
1016
  { name = "beautifulsoup4" },
File without changes
File without changes
File without changes
File without changes