twitter-cli 0.4.2__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.2 → twitter_cli-0.4.4}/PKG-INFO +1 -1
- {twitter_cli-0.4.2 → twitter_cli-0.4.4}/pyproject.toml +1 -1
- {twitter_cli-0.4.2 → twitter_cli-0.4.4}/tests/test_client.py +12 -14
- {twitter_cli-0.4.2 → twitter_cli-0.4.4}/twitter_cli/auth.py +5 -10
- {twitter_cli-0.4.2 → twitter_cli-0.4.4}/twitter_cli/cli.py +12 -9
- {twitter_cli-0.4.2 → twitter_cli-0.4.4}/twitter_cli/client.py +19 -34
- twitter_cli-0.4.4/twitter_cli/constants.py +50 -0
- {twitter_cli-0.4.2 → twitter_cli-0.4.4}/twitter_cli/filter.py +10 -7
- {twitter_cli-0.4.2 → twitter_cli-0.4.4}/twitter_cli/models.py +1 -1
- {twitter_cli-0.4.2 → twitter_cli-0.4.4}/twitter_cli/serialization.py +1 -1
- {twitter_cli-0.4.2 → twitter_cli-0.4.4}/uv.lock +1 -1
- twitter_cli-0.4.2/twitter_cli/constants.py +0 -17
- {twitter_cli-0.4.2 → twitter_cli-0.4.4}/.github/workflows/ci.yml +0 -0
- {twitter_cli-0.4.2 → twitter_cli-0.4.4}/.github/workflows/publish-clawhub.yml +0 -0
- {twitter_cli-0.4.2 → twitter_cli-0.4.4}/.github/workflows/publish.yml +0 -0
- {twitter_cli-0.4.2 → twitter_cli-0.4.4}/.gitignore +0 -0
- {twitter_cli-0.4.2 → twitter_cli-0.4.4}/LICENSE +0 -0
- {twitter_cli-0.4.2 → twitter_cli-0.4.4}/README.md +0 -0
- {twitter_cli-0.4.2 → twitter_cli-0.4.4}/SKILL.md +0 -0
- {twitter_cli-0.4.2 → twitter_cli-0.4.4}/config.yaml +0 -0
- {twitter_cli-0.4.2 → twitter_cli-0.4.4}/tests/conftest.py +0 -0
- {twitter_cli-0.4.2 → twitter_cli-0.4.4}/tests/test_cli.py +0 -0
- {twitter_cli-0.4.2 → twitter_cli-0.4.4}/tests/test_config.py +0 -0
- {twitter_cli-0.4.2 → twitter_cli-0.4.4}/tests/test_config_normalization.py +0 -0
- {twitter_cli-0.4.2 → twitter_cli-0.4.4}/tests/test_filter.py +0 -0
- {twitter_cli-0.4.2 → twitter_cli-0.4.4}/tests/test_serialization.py +0 -0
- {twitter_cli-0.4.2 → twitter_cli-0.4.4}/twitter_cli/__init__.py +0 -0
- {twitter_cli-0.4.2 → twitter_cli-0.4.4}/twitter_cli/config.py +0 -0
- {twitter_cli-0.4.2 → 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
|
|
@@ -213,30 +213,28 @@ class TestBestChromeTarget:
|
|
|
213
213
|
# ── _update_features_from_html ───────────────────────────────────────────
|
|
214
214
|
|
|
215
215
|
class TestUpdateFeaturesFromHtml:
|
|
216
|
-
def
|
|
217
|
-
|
|
216
|
+
def test_updates_existing_feature_flags(self):
|
|
217
|
+
"""Should update existing FEATURES keys, not add new ones."""
|
|
218
218
|
original = dict(FEATURES)
|
|
219
219
|
try:
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
"
|
|
224
|
-
''
|
|
220
|
+
# Use a key that exists in FEATURES
|
|
221
|
+
existing_key = list(FEATURES.keys())[0]
|
|
222
|
+
original_value = FEATURES[existing_key]
|
|
223
|
+
opposite = "false" if original_value else "true"
|
|
224
|
+
html = '"%s":{"value":%s}' % (existing_key, opposite)
|
|
225
225
|
_update_features_from_html(html)
|
|
226
|
-
assert FEATURES[
|
|
227
|
-
assert FEATURES["responsive_web_another_feature"] is False
|
|
228
|
-
assert FEATURES["rweb_some_flag"] is True
|
|
226
|
+
assert FEATURES[existing_key] != original_value
|
|
229
227
|
finally:
|
|
230
|
-
# Restore original state
|
|
231
228
|
FEATURES.clear()
|
|
232
229
|
FEATURES.update(original)
|
|
233
230
|
|
|
234
|
-
def
|
|
231
|
+
def test_does_not_add_new_keys(self):
|
|
232
|
+
"""Should never add keys not already in FEATURES (prevents URL bloat)."""
|
|
235
233
|
original = dict(FEATURES)
|
|
236
234
|
try:
|
|
237
|
-
html = '"
|
|
235
|
+
html = '"responsive_web_brand_new_feature":{"value":true}'
|
|
238
236
|
_update_features_from_html(html)
|
|
239
|
-
assert "
|
|
237
|
+
assert "responsive_web_brand_new_feature" not in FEATURES
|
|
240
238
|
finally:
|
|
241
239
|
FEATURES.clear()
|
|
242
240
|
FEATURES.update(original)
|
|
@@ -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__)
|
|
@@ -53,43 +56,24 @@ TWITTER_OPENAPI_URL = (
|
|
|
53
56
|
"main/src/config/placeholder.json"
|
|
54
57
|
)
|
|
55
58
|
|
|
59
|
+
# Essential features only — keep this list SMALL to avoid 414/431 URI Too Long.
|
|
60
|
+
# Twitter's API defaults missing features to False, so we only need True-valued ones
|
|
61
|
+
# that affect tweet data we actually consume. Each additional key adds ~60 chars to URL.
|
|
56
62
|
_DEFAULT_FEATURES = {
|
|
57
|
-
"rweb_video_screen_enabled": False,
|
|
58
|
-
"profile_label_improvements_pcf_label_in_post_enabled": True,
|
|
59
|
-
"responsive_web_profile_redirect_enabled": False,
|
|
60
|
-
"rweb_tipjar_consumption_enabled": False,
|
|
61
|
-
"verified_phone_label_enabled": False,
|
|
62
63
|
"creator_subscriptions_tweet_preview_api_enabled": True,
|
|
63
|
-
"responsive_web_graphql_timeline_navigation_enabled": True,
|
|
64
|
-
"responsive_web_graphql_skip_user_profile_image_extensions_enabled": False,
|
|
65
|
-
"premium_content_api_read_enabled": False,
|
|
66
64
|
"communities_web_enable_tweet_community_results_fetch": True,
|
|
67
65
|
"c9s_tweet_anatomy_moderator_badge_enabled": True,
|
|
68
|
-
"responsive_web_grok_analyze_button_fetch_trends_enabled": False,
|
|
69
|
-
"responsive_web_grok_analyze_post_followups_enabled": True,
|
|
70
|
-
"responsive_web_jetfuel_frame": True,
|
|
71
|
-
"responsive_web_grok_share_attachment_enabled": True,
|
|
72
|
-
"responsive_web_grok_annotations_enabled": True,
|
|
73
66
|
"articles_preview_enabled": True,
|
|
74
67
|
"responsive_web_edit_tweet_api_enabled": True,
|
|
75
68
|
"graphql_is_translatable_rweb_tweet_is_translatable_enabled": True,
|
|
76
69
|
"view_counts_everywhere_api_enabled": True,
|
|
77
70
|
"longform_notetweets_consumption_enabled": True,
|
|
78
71
|
"responsive_web_twitter_article_tweet_consumption_enabled": True,
|
|
79
|
-
"tweet_awards_web_tipping_enabled": False,
|
|
80
|
-
"content_disclosure_indicator_enabled": True,
|
|
81
|
-
"content_disclosure_ai_generated_indicator_enabled": True,
|
|
82
|
-
"responsive_web_grok_show_grok_translated_post": True,
|
|
83
|
-
"responsive_web_grok_analysis_button_from_backend": True,
|
|
84
|
-
"post_ctas_fetch_enabled": True,
|
|
85
|
-
"freedom_of_speech_not_reach_fetch_enabled": True,
|
|
86
|
-
"standardized_nudges_misinfo": True,
|
|
87
72
|
"tweet_with_visibility_results_prefer_gql_limited_actions_policy_enabled": True,
|
|
88
73
|
"longform_notetweets_rich_text_read_enabled": True,
|
|
89
|
-
"
|
|
90
|
-
"
|
|
91
|
-
"
|
|
92
|
-
"responsive_web_grok_community_note_auto_translation_is_enabled": False,
|
|
74
|
+
"freedom_of_speech_not_reach_fetch_enabled": True,
|
|
75
|
+
"standardized_nudges_misinfo": True,
|
|
76
|
+
"responsive_web_graphql_timeline_navigation_enabled": True,
|
|
93
77
|
"responsive_web_enhance_cards_enabled": False,
|
|
94
78
|
}
|
|
95
79
|
|
|
@@ -143,6 +127,7 @@ def _get_cffi_session():
|
|
|
143
127
|
import os
|
|
144
128
|
proxy = os.environ.get("TWITTER_PROXY", "")
|
|
145
129
|
target = _best_chrome_target()
|
|
130
|
+
sync_chrome_version(target) # align UA/sec-ch-ua with impersonate target
|
|
146
131
|
_cffi_session = _cffi_requests.Session(
|
|
147
132
|
impersonate=target,
|
|
148
133
|
proxies={"https": proxy, "http": proxy} if proxy else None,
|
|
@@ -193,7 +178,7 @@ def _scan_bundles():
|
|
|
193
178
|
_bundles_scanned = True
|
|
194
179
|
|
|
195
180
|
try:
|
|
196
|
-
html = _url_fetch("https://x.com", {"user-agent":
|
|
181
|
+
html = _url_fetch("https://x.com", {"user-agent": get_user_agent()})
|
|
197
182
|
script_pattern = re.compile(
|
|
198
183
|
r'(?:src|href)=["\']'
|
|
199
184
|
r'(https://abs\.twimg\.com/responsive-web/client-web[^"\']+\.js)'
|
|
@@ -226,11 +211,9 @@ def _update_features_from_html(html):
|
|
|
226
211
|
|
|
227
212
|
Twitter embeds feature switch config in inline scripts on the homepage.
|
|
228
213
|
We parse these to keep FEATURES in sync with the current frontend.
|
|
214
|
+
Only UPDATES existing keys — never adds new ones to avoid URL bloat.
|
|
229
215
|
"""
|
|
230
216
|
try:
|
|
231
|
-
# Look for feature flags in inline script content
|
|
232
|
-
# Pattern: "featureSwitch":{"...":{"value":true/false},...}
|
|
233
|
-
# Also try: features:{key:!0, key2:!1, ...} in JS bundles
|
|
234
217
|
feature_pattern = re.compile(
|
|
235
218
|
r'"([a-z][a-z0-9_]+)":\s*\{\s*"value"\s*:\s*(true|false)',
|
|
236
219
|
re.IGNORECASE,
|
|
@@ -239,8 +222,10 @@ def _update_features_from_html(html):
|
|
|
239
222
|
for match in feature_pattern.finditer(html):
|
|
240
223
|
key = match.group(1)
|
|
241
224
|
value = match.group(2).lower() == "true"
|
|
242
|
-
# Only update keys
|
|
243
|
-
|
|
225
|
+
# Only update keys already in FEATURES — never add new ones
|
|
226
|
+
# Adding new keys inflates URL length, causing 414/431 errors
|
|
227
|
+
if key in FEATURES and FEATURES[key] != value:
|
|
228
|
+
logger.debug("Feature flag updated: %s = %s -> %s", key, FEATURES[key], value)
|
|
244
229
|
FEATURES[key] = value
|
|
245
230
|
found += 1
|
|
246
231
|
if found:
|
|
@@ -704,12 +689,12 @@ class TwitterClient:
|
|
|
704
689
|
"X-Twitter-Active-User": "yes",
|
|
705
690
|
"X-Twitter-Auth-Type": "OAuth2Session",
|
|
706
691
|
"X-Twitter-Client-Language": "en",
|
|
707
|
-
"User-Agent":
|
|
692
|
+
"User-Agent": get_user_agent(),
|
|
708
693
|
"Origin": "https://x.com",
|
|
709
694
|
"Referer": "https://x.com",
|
|
710
695
|
"Accept": "*/*",
|
|
711
696
|
"Accept-Language": "en-US,en;q=0.9",
|
|
712
|
-
"sec-ch-ua":
|
|
697
|
+
"sec-ch-ua": get_sec_ch_ua(),
|
|
713
698
|
"sec-ch-ua-mobile": SEC_CH_UA_MOBILE,
|
|
714
699
|
"sec-ch-ua-platform": SEC_CH_UA_PLATFORM,
|
|
715
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
|