twitter-cli 0.2.0__tar.gz → 0.3.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 (26) hide show
  1. {twitter_cli-0.2.0 → twitter_cli-0.3.0}/PKG-INFO +1 -1
  2. {twitter_cli-0.2.0 → twitter_cli-0.3.0}/pyproject.toml +1 -1
  3. {twitter_cli-0.2.0 → twitter_cli-0.3.0}/twitter_cli/auth.py +34 -9
  4. {twitter_cli-0.2.0 → twitter_cli-0.3.0}/twitter_cli/cli.py +6 -1
  5. {twitter_cli-0.2.0 → twitter_cli-0.3.0}/twitter_cli/client.py +14 -5
  6. {twitter_cli-0.2.0 → twitter_cli-0.3.0}/uv.lock +1 -1
  7. {twitter_cli-0.2.0 → twitter_cli-0.3.0}/.github/workflows/ci.yml +0 -0
  8. {twitter_cli-0.2.0 → twitter_cli-0.3.0}/.github/workflows/publish-clawhub.yml +0 -0
  9. {twitter_cli-0.2.0 → twitter_cli-0.3.0}/.github/workflows/publish.yml +0 -0
  10. {twitter_cli-0.2.0 → twitter_cli-0.3.0}/.gitignore +0 -0
  11. {twitter_cli-0.2.0 → twitter_cli-0.3.0}/README.md +0 -0
  12. {twitter_cli-0.2.0 → twitter_cli-0.3.0}/SKILL.md +0 -0
  13. {twitter_cli-0.2.0 → twitter_cli-0.3.0}/config.yaml +0 -0
  14. {twitter_cli-0.2.0 → twitter_cli-0.3.0}/tests/conftest.py +0 -0
  15. {twitter_cli-0.2.0 → twitter_cli-0.3.0}/tests/test_cli.py +0 -0
  16. {twitter_cli-0.2.0 → twitter_cli-0.3.0}/tests/test_config.py +0 -0
  17. {twitter_cli-0.2.0 → twitter_cli-0.3.0}/tests/test_config_normalization.py +0 -0
  18. {twitter_cli-0.2.0 → twitter_cli-0.3.0}/tests/test_filter.py +0 -0
  19. {twitter_cli-0.2.0 → twitter_cli-0.3.0}/tests/test_serialization.py +0 -0
  20. {twitter_cli-0.2.0 → twitter_cli-0.3.0}/twitter_cli/__init__.py +0 -0
  21. {twitter_cli-0.2.0 → twitter_cli-0.3.0}/twitter_cli/config.py +0 -0
  22. {twitter_cli-0.2.0 → twitter_cli-0.3.0}/twitter_cli/constants.py +0 -0
  23. {twitter_cli-0.2.0 → twitter_cli-0.3.0}/twitter_cli/filter.py +0 -0
  24. {twitter_cli-0.2.0 → twitter_cli-0.3.0}/twitter_cli/formatter.py +0 -0
  25. {twitter_cli-0.2.0 → twitter_cli-0.3.0}/twitter_cli/models.py +0 -0
  26. {twitter_cli-0.2.0 → twitter_cli-0.3.0}/twitter_cli/serialization.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: twitter-cli
3
- Version: 0.2.0
3
+ Version: 0.3.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
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "twitter-cli"
7
- version = "0.2.0"
7
+ version = "0.3.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"
@@ -3,6 +3,7 @@
3
3
  Supports:
4
4
  1. Environment variables: TWITTER_AUTH_TOKEN + TWITTER_CT0
5
5
  2. Auto-extract from browser via browser-cookie3 (subprocess)
6
+ Extracts ALL Twitter cookies for full browser-like fingerprint.
6
7
  """
7
8
 
8
9
  from __future__ import annotations
@@ -30,8 +31,8 @@ def load_from_env() -> Optional[Dict[str, str]]:
30
31
  return None
31
32
 
32
33
 
33
- def verify_cookies(auth_token, ct0):
34
- # type: (str, str) -> Dict[str, Any]
34
+ def verify_cookies(auth_token, ct0, cookie_string=None):
35
+ # type: (str, str, Optional[str]) -> Dict[str, Any]
35
36
  """Verify cookies by calling a Twitter API endpoint.
36
37
 
37
38
  Uses curl_cffi for proper TLS fingerprint.
@@ -43,16 +44,23 @@ def verify_cookies(auth_token, ct0):
43
44
  "https://x.com/i/api/1.1/account/settings.json",
44
45
  ]
45
46
 
47
+ # Use full cookie string if available, otherwise minimal
48
+ cookie_header = cookie_string or "auth_token=%s; ct0=%s" % (auth_token, ct0)
49
+
46
50
  headers = {
47
51
  "Authorization": "Bearer %s" % BEARER_TOKEN,
48
- "Cookie": "auth_token=%s; ct0=%s" % (auth_token, ct0),
52
+ "Cookie": cookie_header,
49
53
  "X-Csrf-Token": ct0,
50
54
  "X-Twitter-Active-User": "yes",
51
55
  "X-Twitter-Auth-Type": "OAuth2Session",
52
56
  "User-Agent": USER_AGENT,
53
57
  }
54
58
 
55
- session = _cffi_requests.Session(impersonate="chrome133")
59
+ proxy = os.environ.get("TWITTER_PROXY", "")
60
+ session = _cffi_requests.Session(
61
+ impersonate="chrome133",
62
+ proxies={"https": proxy, "http": proxy} if proxy else None,
63
+ )
56
64
 
57
65
  for url in urls:
58
66
  try:
@@ -78,11 +86,14 @@ def verify_cookies(auth_token, ct0):
78
86
 
79
87
 
80
88
  def extract_from_browser() -> Optional[Dict[str, str]]:
81
- """Auto-extract cookies from local browser using browser-cookie3.
89
+ """Auto-extract ALL Twitter cookies from local browser using browser-cookie3.
90
+
91
+ Extracts every cookie for .x.com and .twitter.com domains, not just
92
+ auth_token and ct0. This makes requests indistinguishable from real
93
+ browser traffic at the cookie level.
82
94
 
83
95
  Tries browsers in order: Chrome -> Edge -> Firefox -> Brave.
84
- Runs in a subprocess to avoid SQLite database lock issues when the
85
- browser is running.
96
+ Runs in a subprocess to avoid SQLite database lock issues.
86
97
  """
87
98
  extract_script = '''
88
99
  import json, sys
@@ -105,6 +116,7 @@ for name, fn in browsers:
105
116
  except Exception:
106
117
  continue
107
118
  result = {}
119
+ all_cookies = {}
108
120
  for cookie in jar:
109
121
  domain = cookie.domain or ""
110
122
  if domain.endswith(".x.com") or domain.endswith(".twitter.com") or domain in ("x.com", "twitter.com", ".x.com", ".twitter.com"):
@@ -112,8 +124,12 @@ for name, fn in browsers:
112
124
  result["auth_token"] = cookie.value
113
125
  elif cookie.name == "ct0":
114
126
  result["ct0"] = cookie.value
127
+ # Collect ALL cookies for full browser fingerprint
128
+ if cookie.name and cookie.value:
129
+ all_cookies[cookie.name] = cookie.value
115
130
  if "auth_token" in result and "ct0" in result:
116
131
  result["browser"] = name
132
+ result["all_cookies"] = all_cookies
117
133
  print(json.dumps(result))
118
134
  sys.exit(0)
119
135
 
@@ -149,7 +165,15 @@ sys.exit(1)
149
165
  if "error" in data:
150
166
  return None
151
167
  logger.info("Found cookies in %s", data.get("browser", "unknown"))
152
- return {"auth_token": data["auth_token"], "ct0": data["ct0"]}
168
+
169
+ # Build full cookie string from all extracted cookies
170
+ cookies = {"auth_token": data["auth_token"], "ct0": data["ct0"]}
171
+ all_cookies = data.get("all_cookies", {})
172
+ if all_cookies:
173
+ cookie_str = "; ".join("%s=%s" % (k, v) for k, v in all_cookies.items())
174
+ cookies["cookie_string"] = cookie_str
175
+ logger.info("Extracted %d total cookies for full browser fingerprint", len(all_cookies))
176
+ return cookies
153
177
  except (subprocess.TimeoutExpired, json.JSONDecodeError, KeyError, FileNotFoundError):
154
178
  return None
155
179
 
@@ -178,5 +202,6 @@ def get_cookies() -> Dict[str, str]:
178
202
  )
179
203
 
180
204
  # Verify only for explicit auth failures; transient endpoint issues are tolerated.
181
- verify_cookies(cookies["auth_token"], cookies["ct0"])
205
+ verify_cookies(cookies["auth_token"], cookies["ct0"], cookies.get("cookie_string"))
182
206
  return cookies
207
+
@@ -80,7 +80,12 @@ def _get_client(config=None):
80
80
  console.print("\n🔐 Getting Twitter cookies...")
81
81
  cookies = get_cookies()
82
82
  rate_limit_config = (config or {}).get("rateLimit")
83
- return TwitterClient(cookies["auth_token"], cookies["ct0"], rate_limit_config)
83
+ return TwitterClient(
84
+ cookies["auth_token"],
85
+ cookies["ct0"],
86
+ rate_limit_config,
87
+ cookie_string=cookies.get("cookie_string"),
88
+ )
84
89
 
85
90
 
86
91
  def _resolve_fetch_count(max_count, configured):
@@ -23,6 +23,7 @@ logger = logging.getLogger(__name__)
23
23
 
24
24
  # Shared curl_cffi session — impersonates Chrome 133 TLS/JA3/HTTP2 fingerprint
25
25
  _cffi_session = None # type: Optional[Any] # lazy init
26
+ _cffi_proxy = None # type: Optional[str]
26
27
 
27
28
 
28
29
  FALLBACK_QUERY_IDS = {
@@ -110,10 +111,17 @@ class TwitterAPIError(RuntimeError):
110
111
 
111
112
  def _get_cffi_session():
112
113
  # type: () -> Any
113
- """Return shared curl_cffi session with Chrome impersonation."""
114
+ """Return shared curl_cffi session with Chrome impersonation and optional proxy."""
114
115
  global _cffi_session
115
116
  if _cffi_session is None:
116
- _cffi_session = _cffi_requests.Session(impersonate="chrome133")
117
+ import os
118
+ proxy = os.environ.get("TWITTER_PROXY", "")
119
+ _cffi_session = _cffi_requests.Session(
120
+ impersonate="chrome133",
121
+ proxies={"https": proxy, "http": proxy} if proxy else None,
122
+ )
123
+ if proxy:
124
+ logger.info("Using proxy: %s", proxy[:20] + "...")
117
125
  return _cffi_session
118
126
 
119
127
 
@@ -235,10 +243,11 @@ _ABSOLUTE_MAX_COUNT = 500
235
243
  class TwitterClient:
236
244
  """Twitter GraphQL API client using cookie authentication."""
237
245
 
238
- def __init__(self, auth_token, ct0, rate_limit_config=None):
239
- # type: (str, str, Optional[Dict[str, Any]]) -> None
246
+ def __init__(self, auth_token, ct0, rate_limit_config=None, cookie_string=None):
247
+ # type: (str, str, Optional[Dict[str, Any]], Optional[str]) -> None
240
248
  self._auth_token = auth_token
241
249
  self._ct0 = ct0
250
+ self._cookie_string = cookie_string # Full browser cookie string
242
251
  rl = rate_limit_config or {}
243
252
  self._request_delay = float(rl.get("requestDelay", 2.5))
244
253
  self._max_retries = int(rl.get("maxRetries", 3))
@@ -599,7 +608,7 @@ class TwitterClient:
599
608
  """Build shared headers for authenticated API calls."""
600
609
  headers = {
601
610
  "Authorization": "Bearer %s" % BEARER_TOKEN,
602
- "Cookie": "auth_token=%s; ct0=%s" % (self._auth_token, self._ct0),
611
+ "Cookie": self._cookie_string or "auth_token=%s; ct0=%s" % (self._auth_token, self._ct0),
603
612
  "X-Csrf-Token": self._ct0,
604
613
  "X-Twitter-Active-User": "yes",
605
614
  "X-Twitter-Auth-Type": "OAuth2Session",
@@ -1116,7 +1116,7 @@ wheels = [
1116
1116
 
1117
1117
  [[package]]
1118
1118
  name = "twitter-cli"
1119
- version = "0.1.1"
1119
+ version = "0.2.0"
1120
1120
  source = { editable = "." }
1121
1121
  dependencies = [
1122
1122
  { name = "beautifulsoup4" },
File without changes
File without changes
File without changes
File without changes