twitter-cli 0.4.3__tar.gz → 0.4.5__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 (29) hide show
  1. {twitter_cli-0.4.3 → twitter_cli-0.4.5}/PKG-INFO +13 -3
  2. {twitter_cli-0.4.3 → twitter_cli-0.4.5}/README.md +12 -2
  3. {twitter_cli-0.4.3 → twitter_cli-0.4.5}/SKILL.md +9 -1
  4. {twitter_cli-0.4.3 → twitter_cli-0.4.5}/pyproject.toml +1 -1
  5. {twitter_cli-0.4.3 → twitter_cli-0.4.5}/twitter_cli/auth.py +5 -10
  6. {twitter_cli-0.4.3 → twitter_cli-0.4.5}/twitter_cli/cli.py +14 -11
  7. {twitter_cli-0.4.3 → twitter_cli-0.4.5}/twitter_cli/client.py +8 -4
  8. twitter_cli-0.4.5/twitter_cli/constants.py +50 -0
  9. {twitter_cli-0.4.3 → twitter_cli-0.4.5}/twitter_cli/filter.py +10 -7
  10. {twitter_cli-0.4.3 → twitter_cli-0.4.5}/twitter_cli/models.py +1 -1
  11. {twitter_cli-0.4.3 → twitter_cli-0.4.5}/twitter_cli/serialization.py +1 -1
  12. {twitter_cli-0.4.3 → twitter_cli-0.4.5}/uv.lock +1 -1
  13. twitter_cli-0.4.3/twitter_cli/constants.py +0 -17
  14. {twitter_cli-0.4.3 → twitter_cli-0.4.5}/.github/workflows/ci.yml +0 -0
  15. {twitter_cli-0.4.3 → twitter_cli-0.4.5}/.github/workflows/publish-clawhub.yml +0 -0
  16. {twitter_cli-0.4.3 → twitter_cli-0.4.5}/.github/workflows/publish.yml +0 -0
  17. {twitter_cli-0.4.3 → twitter_cli-0.4.5}/.gitignore +0 -0
  18. {twitter_cli-0.4.3 → twitter_cli-0.4.5}/LICENSE +0 -0
  19. {twitter_cli-0.4.3 → twitter_cli-0.4.5}/config.yaml +0 -0
  20. {twitter_cli-0.4.3 → twitter_cli-0.4.5}/tests/conftest.py +0 -0
  21. {twitter_cli-0.4.3 → twitter_cli-0.4.5}/tests/test_cli.py +0 -0
  22. {twitter_cli-0.4.3 → twitter_cli-0.4.5}/tests/test_client.py +0 -0
  23. {twitter_cli-0.4.3 → twitter_cli-0.4.5}/tests/test_config.py +0 -0
  24. {twitter_cli-0.4.3 → twitter_cli-0.4.5}/tests/test_config_normalization.py +0 -0
  25. {twitter_cli-0.4.3 → twitter_cli-0.4.5}/tests/test_filter.py +0 -0
  26. {twitter_cli-0.4.3 → twitter_cli-0.4.5}/tests/test_serialization.py +0 -0
  27. {twitter_cli-0.4.3 → twitter_cli-0.4.5}/twitter_cli/__init__.py +0 -0
  28. {twitter_cli-0.4.3 → twitter_cli-0.4.5}/twitter_cli/config.py +0 -0
  29. {twitter_cli-0.4.3 → twitter_cli-0.4.5}/twitter_cli/formatter.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: twitter-cli
3
- Version: 0.4.3
3
+ Version: 0.4.5
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 133 JA3/HTTP2
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 133 JA3/HTTP2
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 133 JA3/HTTP2
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 133 JA3/HTTP2
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.10+)
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`.
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "twitter-cli"
7
- version = "0.4.3"
7
+ version = "0.4.5"
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"
@@ -17,9 +17,7 @@ import subprocess
17
17
  import sys
18
18
  from typing import Dict, Optional
19
19
 
20
- from curl_cffi import requests as _cffi_requests
21
-
22
- from .constants import BEARER_TOKEN, USER_AGENT
20
+ from .constants import BEARER_TOKEN, get_user_agent
23
21
 
24
22
  logger = logging.getLogger(__name__)
25
23
 
@@ -49,7 +47,7 @@ def verify_cookies(auth_token, ct0, cookie_string=None):
49
47
  Tries multiple endpoints. Only raises on clear auth failures (401/403).
50
48
  For other errors (404, network), returns empty dict (proceed without verification).
51
49
  """
52
- from .client import _best_chrome_target
50
+ from .client import _get_cffi_session
53
51
 
54
52
  urls = [
55
53
  "https://api.x.com/1.1/account/verify_credentials.json",
@@ -65,14 +63,11 @@ def verify_cookies(auth_token, ct0, cookie_string=None):
65
63
  "X-Csrf-Token": ct0,
66
64
  "X-Twitter-Active-User": "yes",
67
65
  "X-Twitter-Auth-Type": "OAuth2Session",
68
- "User-Agent": USER_AGENT,
66
+ "User-Agent": get_user_agent(),
69
67
  }
70
68
 
71
- proxy = os.environ.get("TWITTER_PROXY", "")
72
- session = _cffi_requests.Session(
73
- impersonate=_best_chrome_target(),
74
- proxies={"https": proxy, "http": proxy} if proxy else None,
75
- )
69
+ # Reuse the shared curl_cffi session for consistent TLS fingerprint
70
+ session = _get_cffi_session()
76
71
 
77
72
  for url in urls:
78
73
  try:
@@ -244,8 +244,9 @@ def user(screen_name):
244
244
  @click.argument("screen_name")
245
245
  @click.option("--max", "-n", "max_count", type=int, default=20, help="Max number of tweets to fetch.")
246
246
  @click.option("--json", "as_json", is_flag=True, help="Output as JSON.")
247
- def user_posts(screen_name, max_count, as_json):
248
- # type: (str, int, bool) -> None
247
+ @click.option("--output", "-o", "output_file", type=str, default=None, help="Save tweets to JSON file.")
248
+ def user_posts(screen_name, max_count, as_json, output_file):
249
+ # type: (str, int, bool, Optional[str]) -> None
249
250
  """List a user's tweets. SCREEN_NAME is the @handle (without @)."""
250
251
  screen_name = screen_name.lstrip("@")
251
252
  config = load_config()
@@ -258,7 +259,7 @@ def user_posts(screen_name, max_count, as_json):
258
259
  sys.exit(1)
259
260
  _fetch_and_display(
260
261
  lambda count: client.fetch_user_tweets(profile.id, count),
261
- "@%s tweets" % screen_name, "📝", max_count, as_json, None, False, config,
262
+ "@%s tweets" % screen_name, "📝", max_count, as_json, output_file, False, config,
262
263
  )
263
264
 
264
265
 
@@ -277,15 +278,16 @@ SEARCH_PRODUCTS = ["Top", "Latest", "Photos", "Videos"]
277
278
  )
278
279
  @click.option("--max", "-n", "max_count", type=int, default=20, help="Max number of tweets to fetch.")
279
280
  @click.option("--json", "as_json", is_flag=True, help="Output as JSON.")
281
+ @click.option("--output", "-o", "output_file", type=str, default=None, help="Save tweets to JSON file.")
280
282
  @click.option("--filter", "do_filter", is_flag=True, help="Enable score-based filtering.")
281
- def search(query, product, max_count, as_json, do_filter):
282
- # type: (str, str, int, bool, bool) -> None
283
+ def search(query, product, max_count, as_json, output_file, do_filter):
284
+ # type: (str, str, int, bool, Optional[str], bool) -> None
283
285
  """Search tweets by QUERY string."""
284
286
  config = load_config()
285
287
  client = _get_client(config)
286
288
  _fetch_and_display(
287
289
  lambda count: client.fetch_search(query, count, product),
288
- "'%s' (%s)" % (query, product), "🔍", max_count, as_json, None, do_filter, config,
290
+ "'%s' (%s)" % (query, product), "🔍", max_count, as_json, output_file, do_filter, config,
289
291
  )
290
292
 
291
293
 
@@ -293,9 +295,10 @@ def search(query, product, max_count, as_json, do_filter):
293
295
  @click.argument("screen_name")
294
296
  @click.option("--max", "-n", "max_count", type=int, default=20, help="Max number of tweets to fetch.")
295
297
  @click.option("--json", "as_json", is_flag=True, help="Output as JSON.")
298
+ @click.option("--output", "-o", "output_file", type=str, default=None, help="Save tweets to JSON file.")
296
299
  @click.option("--filter", "do_filter", is_flag=True, help="Enable score-based filtering.")
297
- def likes(screen_name, max_count, as_json, do_filter):
298
- # type: (str, int, bool, bool) -> None
300
+ def likes(screen_name, max_count, as_json, output_file, do_filter):
301
+ # type: (str, int, bool, Optional[str], bool) -> None
299
302
  """Show tweets liked by a user. SCREEN_NAME is the @handle (without @)."""
300
303
  screen_name = screen_name.lstrip("@")
301
304
  config = load_config()
@@ -308,7 +311,7 @@ def likes(screen_name, max_count, as_json, do_filter):
308
311
  sys.exit(1)
309
312
  _fetch_and_display(
310
313
  lambda count: client.fetch_user_likes(profile.id, count),
311
- "@%s likes" % screen_name, "❤️", max_count, as_json, None, do_filter, config,
314
+ "@%s likes" % screen_name, "❤️", max_count, as_json, output_file, do_filter, config,
312
315
  )
313
316
 
314
317
 
@@ -483,7 +486,7 @@ def unlike(tweet_id):
483
486
 
484
487
  @cli.command()
485
488
  @click.argument("tweet_id")
486
- def rt(tweet_id):
489
+ def retweet(tweet_id):
487
490
  # type: (str,) -> None
488
491
  """Retweet a tweet. TWEET_ID is the numeric tweet ID."""
489
492
  _write_action("🔄", "Retweeting", "retweet", tweet_id)
@@ -491,7 +494,7 @@ def rt(tweet_id):
491
494
 
492
495
  @cli.command()
493
496
  @click.argument("tweet_id")
494
- def unrt(tweet_id):
497
+ def unretweet(tweet_id):
495
498
  # type: (str,) -> None
496
499
  """Undo a retweet. TWEET_ID is the numeric tweet ID."""
497
500
  _write_action("🔄", "Undoing retweet", "unretweet", tweet_id)
@@ -15,7 +15,10 @@ from curl_cffi import requests as _cffi_requests
15
15
  from x_client_transaction import ClientTransaction
16
16
  from x_client_transaction.utils import generate_headers as _gen_ct_headers, get_ondemand_file_url
17
17
 
18
- from .constants import BEARER_TOKEN, USER_AGENT, SEC_CH_UA, SEC_CH_UA_MOBILE, SEC_CH_UA_PLATFORM
18
+ from .constants import (
19
+ BEARER_TOKEN, SEC_CH_UA_MOBILE, SEC_CH_UA_PLATFORM,
20
+ get_sec_ch_ua, get_user_agent, sync_chrome_version,
21
+ )
19
22
  from .models import Author, Metrics, Tweet, TweetMedia, UserProfile
20
23
 
21
24
  logger = logging.getLogger(__name__)
@@ -124,6 +127,7 @@ def _get_cffi_session():
124
127
  import os
125
128
  proxy = os.environ.get("TWITTER_PROXY", "")
126
129
  target = _best_chrome_target()
130
+ sync_chrome_version(target) # align UA/sec-ch-ua with impersonate target
127
131
  _cffi_session = _cffi_requests.Session(
128
132
  impersonate=target,
129
133
  proxies={"https": proxy, "http": proxy} if proxy else None,
@@ -174,7 +178,7 @@ def _scan_bundles():
174
178
  _bundles_scanned = True
175
179
 
176
180
  try:
177
- html = _url_fetch("https://x.com", {"user-agent": USER_AGENT})
181
+ html = _url_fetch("https://x.com", {"user-agent": get_user_agent()})
178
182
  script_pattern = re.compile(
179
183
  r'(?:src|href)=["\']'
180
184
  r'(https://abs\.twimg\.com/responsive-web/client-web[^"\']+\.js)'
@@ -685,12 +689,12 @@ class TwitterClient:
685
689
  "X-Twitter-Active-User": "yes",
686
690
  "X-Twitter-Auth-Type": "OAuth2Session",
687
691
  "X-Twitter-Client-Language": "en",
688
- "User-Agent": USER_AGENT,
692
+ "User-Agent": get_user_agent(),
689
693
  "Origin": "https://x.com",
690
694
  "Referer": "https://x.com",
691
695
  "Accept": "*/*",
692
696
  "Accept-Language": "en-US,en;q=0.9",
693
- "sec-ch-ua": SEC_CH_UA,
697
+ "sec-ch-ua": get_sec_ch_ua(),
694
698
  "sec-ch-ua-mobile": SEC_CH_UA_MOBILE,
695
699
  "sec-ch-ua-platform": SEC_CH_UA_PLATFORM,
696
700
  "Sec-Fetch-Dest": "empty",
@@ -0,0 +1,50 @@
1
+ """Shared constants for twitter-cli."""
2
+
3
+ import re
4
+
5
+ BEARER_TOKEN = (
6
+ "AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs"
7
+ "%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA"
8
+ )
9
+
10
+ # Default Chrome version — updated by _best_chrome_target() at runtime
11
+ _DEFAULT_CHROME_VERSION = "133"
12
+ _chrome_version = _DEFAULT_CHROME_VERSION # mutable, set by sync_chrome_version()
13
+
14
+
15
+ def sync_chrome_version(impersonate_target):
16
+ # type: (str) -> None
17
+ """Sync USER_AGENT / SEC_CH_UA with the actual impersonate target.
18
+
19
+ Called once when _get_cffi_session() picks a target (e.g. "chrome136").
20
+ """
21
+ global _chrome_version
22
+ match = re.search(r"(\d+)", impersonate_target)
23
+ if match:
24
+ _chrome_version = match.group(1)
25
+
26
+
27
+ def get_user_agent():
28
+ # type: () -> str
29
+ return (
30
+ "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) "
31
+ "AppleWebKit/537.36 (KHTML, like Gecko) "
32
+ "Chrome/%s.0.0.0 Safari/537.36" % _chrome_version
33
+ )
34
+
35
+
36
+ def get_sec_ch_ua():
37
+ # type: () -> str
38
+ return '"Chromium";v="%s", "Not(A:Brand";v="99", "Google Chrome";v="%s"' % (
39
+ _chrome_version, _chrome_version,
40
+ )
41
+
42
+
43
+ # Static Client Hints
44
+ SEC_CH_UA_MOBILE = "?0"
45
+ SEC_CH_UA_PLATFORM = '"macOS"'
46
+
47
+ # Legacy aliases — modules that import these get the default value.
48
+ # _build_headers() should use get_user_agent() / get_sec_ch_ua() instead.
49
+ USER_AGENT = get_user_agent()
50
+ SEC_CH_UA = get_sec_ch_ua()
@@ -21,7 +21,7 @@ DEFAULT_WEIGHTS = {
21
21
 
22
22
 
23
23
  def score_tweet(tweet, weights=None):
24
- # type: (Tweet, Optional[FilterWeights]) -> float
24
+ # type: (Tweet, Optional[Dict[str, float]]) -> float
25
25
  """Calculate engagement score for a single tweet.
26
26
 
27
27
  Formula:
@@ -30,15 +30,18 @@ def score_tweet(tweet, weights=None):
30
30
  + w_replies × replies
31
31
  + w_bookmarks × bookmarks
32
32
  + w_views_log × log10(views)
33
+
34
+ Args:
35
+ weights: Pre-built weight dict. If None, uses DEFAULT_WEIGHTS.
33
36
  """
34
- weight_map = _build_weights(weights or {})
37
+ w = weights or DEFAULT_WEIGHTS
35
38
  m = tweet.metrics
36
39
  return (
37
- weight_map["likes"] * m.likes
38
- + weight_map["retweets"] * m.retweets
39
- + weight_map["replies"] * m.replies
40
- + weight_map["bookmarks"] * m.bookmarks
41
- + weight_map["views_log"] * math.log10(max(m.views, 1))
40
+ w.get("likes", 1.0) * m.likes
41
+ + w.get("retweets", 3.0) * m.retweets
42
+ + w.get("replies", 2.0) * m.replies
43
+ + w.get("bookmarks", 5.0) * m.bookmarks
44
+ + w.get("views_log", 0.5) * math.log10(max(m.views, 1))
42
45
  )
43
46
 
44
47
 
@@ -49,7 +49,7 @@ class Tweet:
49
49
  lang: str = ""
50
50
  retweeted_by: Optional[str] = None
51
51
  quoted_tweet: Optional[Tweet] = None
52
- score: float = 0.0
52
+ score: Optional[float] = None
53
53
 
54
54
 
55
55
  @dataclass
@@ -112,7 +112,7 @@ def tweet_from_dict(data: Dict[str, Any]) -> Tweet:
112
112
  lang=str(data.get("lang") or ""),
113
113
  retweeted_by=_optional_str(data.get("retweetedBy")),
114
114
  quoted_tweet=quoted_tweet,
115
- score=float(data.get("score") or 0.0),
115
+ score=float(data["score"]) if data.get("score") is not None else None,
116
116
  )
117
117
 
118
118
 
@@ -950,7 +950,7 @@ wheels = [
950
950
 
951
951
  [[package]]
952
952
  name = "twitter-cli"
953
- version = "0.4.2"
953
+ version = "0.4.4"
954
954
  source = { editable = "." }
955
955
  dependencies = [
956
956
  { name = "beautifulsoup4" },
@@ -1,17 +0,0 @@
1
- """Shared constants for twitter-cli."""
2
-
3
- BEARER_TOKEN = (
4
- "AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs"
5
- "%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA"
6
- )
7
-
8
- USER_AGENT = (
9
- "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) "
10
- "AppleWebKit/537.36 (KHTML, like Gecko) "
11
- "Chrome/133.0.0.0 Safari/537.36"
12
- )
13
-
14
- # Chrome Client Hints — sent by modern Chrome on every request
15
- SEC_CH_UA = '"Chromium";v="133", "Not(A:Brand";v="99", "Google Chrome";v="133"'
16
- SEC_CH_UA_MOBILE = "?0"
17
- SEC_CH_UA_PLATFORM = '"macOS"'
File without changes
File without changes
File without changes