twitter-cli 0.4.3__tar.gz → 0.4.4__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.3 → twitter_cli-0.4.4}/PKG-INFO +1 -1
- {twitter_cli-0.4.3 → twitter_cli-0.4.4}/pyproject.toml +1 -1
- {twitter_cli-0.4.3 → twitter_cli-0.4.4}/twitter_cli/auth.py +5 -10
- {twitter_cli-0.4.3 → twitter_cli-0.4.4}/twitter_cli/cli.py +12 -9
- {twitter_cli-0.4.3 → twitter_cli-0.4.4}/twitter_cli/client.py +8 -4
- twitter_cli-0.4.4/twitter_cli/constants.py +50 -0
- {twitter_cli-0.4.3 → twitter_cli-0.4.4}/twitter_cli/filter.py +10 -7
- {twitter_cli-0.4.3 → twitter_cli-0.4.4}/twitter_cli/models.py +1 -1
- {twitter_cli-0.4.3 → twitter_cli-0.4.4}/twitter_cli/serialization.py +1 -1
- {twitter_cli-0.4.3 → twitter_cli-0.4.4}/uv.lock +1 -1
- twitter_cli-0.4.3/twitter_cli/constants.py +0 -17
- {twitter_cli-0.4.3 → twitter_cli-0.4.4}/.github/workflows/ci.yml +0 -0
- {twitter_cli-0.4.3 → twitter_cli-0.4.4}/.github/workflows/publish-clawhub.yml +0 -0
- {twitter_cli-0.4.3 → twitter_cli-0.4.4}/.github/workflows/publish.yml +0 -0
- {twitter_cli-0.4.3 → twitter_cli-0.4.4}/.gitignore +0 -0
- {twitter_cli-0.4.3 → twitter_cli-0.4.4}/LICENSE +0 -0
- {twitter_cli-0.4.3 → twitter_cli-0.4.4}/README.md +0 -0
- {twitter_cli-0.4.3 → twitter_cli-0.4.4}/SKILL.md +0 -0
- {twitter_cli-0.4.3 → twitter_cli-0.4.4}/config.yaml +0 -0
- {twitter_cli-0.4.3 → twitter_cli-0.4.4}/tests/conftest.py +0 -0
- {twitter_cli-0.4.3 → twitter_cli-0.4.4}/tests/test_cli.py +0 -0
- {twitter_cli-0.4.3 → twitter_cli-0.4.4}/tests/test_client.py +0 -0
- {twitter_cli-0.4.3 → twitter_cli-0.4.4}/tests/test_config.py +0 -0
- {twitter_cli-0.4.3 → twitter_cli-0.4.4}/tests/test_config_normalization.py +0 -0
- {twitter_cli-0.4.3 → twitter_cli-0.4.4}/tests/test_filter.py +0 -0
- {twitter_cli-0.4.3 → twitter_cli-0.4.4}/tests/test_serialization.py +0 -0
- {twitter_cli-0.4.3 → twitter_cli-0.4.4}/twitter_cli/__init__.py +0 -0
- {twitter_cli-0.4.3 → twitter_cli-0.4.4}/twitter_cli/config.py +0 -0
- {twitter_cli-0.4.3 → twitter_cli-0.4.4}/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
|
+
Version: 0.4.4
|
|
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
|
|
@@ -17,9 +17,7 @@ import subprocess
|
|
|
17
17
|
import sys
|
|
18
18
|
from typing import Dict, Optional
|
|
19
19
|
|
|
20
|
-
from
|
|
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
|
|
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":
|
|
66
|
+
"User-Agent": get_user_agent(),
|
|
69
67
|
}
|
|
70
68
|
|
|
71
|
-
|
|
72
|
-
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
|
-
|
|
248
|
-
|
|
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,
|
|
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,
|
|
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,
|
|
314
|
+
"@%s likes" % screen_name, "❤️", max_count, as_json, output_file, do_filter, config,
|
|
312
315
|
)
|
|
313
316
|
|
|
314
317
|
|
|
@@ -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
|
|
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":
|
|
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":
|
|
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":
|
|
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[
|
|
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
|
-
|
|
37
|
+
w = weights or DEFAULT_WEIGHTS
|
|
35
38
|
m = tweet.metrics
|
|
36
39
|
return (
|
|
37
|
-
|
|
38
|
-
+
|
|
39
|
-
+
|
|
40
|
-
+
|
|
41
|
-
+
|
|
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
|
|
|
@@ -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")
|
|
115
|
+
score=float(data["score"]) if data.get("score") is not None else None,
|
|
116
116
|
)
|
|
117
117
|
|
|
118
118
|
|
|
@@ -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
|
|
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
|