chore: code review cleanup + bump v0.8.4
- Remove _get_client_for_output() compat shim (replaced by direct _get_client calls) - Remove unused inspect import - Fix redundant branch in constants.get_accept_language() - Add TWITTER_BROWSER docs to README (en + zh) - Update all test monkeypatch signatures - Bump version to 0.8.4
This commit is contained in:
@@ -32,7 +32,6 @@ from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import re
|
||||
import inspect
|
||||
import sys
|
||||
import time
|
||||
import urllib.parse
|
||||
@@ -153,17 +152,7 @@ def _get_client(config=None, quiet=False):
|
||||
)
|
||||
|
||||
|
||||
def _get_client_for_output(config=None, quiet=False):
|
||||
# type: (Optional[Dict[str, Any]], bool) -> TwitterClient
|
||||
"""Call _get_client while staying compatible with monkeypatched legacy signatures."""
|
||||
try:
|
||||
signature = inspect.signature(_get_client)
|
||||
except (TypeError, ValueError):
|
||||
signature = None
|
||||
|
||||
if signature and "quiet" in signature.parameters:
|
||||
return _get_client(config, quiet=quiet)
|
||||
return _get_client(config)
|
||||
|
||||
|
||||
def _exit_with_error(exc):
|
||||
@@ -417,7 +406,7 @@ def feed(ctx, feed_type, max_count, as_json, as_yaml, input_file, output_file, d
|
||||
console.print(" Loaded %d tweets" % len(tweets))
|
||||
else:
|
||||
fetch_count = _resolve_configured_count(config, max_count)
|
||||
client = _get_client_for_output(config, quiet=not rich_output)
|
||||
client = _get_client(config, quiet=not rich_output)
|
||||
label = "following feed" if feed_type == "following" else "home timeline"
|
||||
if rich_output:
|
||||
console.print("📡 Fetching %s (%d tweets)...\n" % (label, fetch_count))
|
||||
@@ -507,7 +496,7 @@ def user(screen_name, as_json, as_yaml):
|
||||
config = load_config()
|
||||
try:
|
||||
rich_output = use_rich_output(as_json=as_json, as_yaml=as_yaml)
|
||||
client = _get_client_for_output(config, quiet=not rich_output)
|
||||
client = _get_client(config, quiet=not rich_output)
|
||||
if rich_output:
|
||||
console.print("👤 Fetching user @%s..." % screen_name)
|
||||
profile = client.fetch_user(screen_name)
|
||||
@@ -534,7 +523,7 @@ def user_posts(ctx, screen_name, max_count, as_json, as_yaml, output_file, full_
|
||||
config = load_config()
|
||||
def _run():
|
||||
rich_output = use_rich_output(as_json=as_json, as_yaml=as_yaml, compact=compact)
|
||||
client = _get_client_for_output(config, quiet=not rich_output)
|
||||
client = _get_client(config, quiet=not rich_output)
|
||||
if rich_output:
|
||||
console.print("👤 Fetching @%s's profile..." % screen_name)
|
||||
profile = client.fetch_user(screen_name)
|
||||
@@ -619,7 +608,7 @@ def search(ctx, query, product, from_user, to_user, lang, since, until, has, exc
|
||||
config = load_config()
|
||||
def _run():
|
||||
rich_output = use_rich_output(as_json=as_json, as_yaml=as_yaml, compact=compact)
|
||||
client = _get_client_for_output(config, quiet=not rich_output)
|
||||
client = _get_client(config, quiet=not rich_output)
|
||||
_fetch_and_display(
|
||||
lambda count: client.fetch_search(composed_query, count, product),
|
||||
"'%s' (%s)" % (composed_query, product), "🔍", max_count, as_json, as_yaml, output_file, do_filter, config,
|
||||
@@ -648,7 +637,7 @@ def likes(ctx, screen_name, max_count, as_json, as_yaml, output_file, do_filter,
|
||||
config = load_config()
|
||||
def _run():
|
||||
rich_output = use_rich_output(as_json=as_json, as_yaml=as_yaml, compact=compact)
|
||||
client = _get_client_for_output(config, quiet=not rich_output)
|
||||
client = _get_client(config, quiet=not rich_output)
|
||||
if rich_output:
|
||||
console.print("👤 Fetching @%s's profile..." % screen_name)
|
||||
profile = client.fetch_user(screen_name)
|
||||
@@ -694,7 +683,7 @@ def tweet(ctx, tweet_id, max_count, full_text, as_json, as_yaml):
|
||||
config = load_config()
|
||||
rich_output = use_rich_output(as_json=as_json, as_yaml=as_yaml, compact=compact)
|
||||
try:
|
||||
client = _get_client_for_output(config, quiet=not rich_output)
|
||||
client = _get_client(config, quiet=not rich_output)
|
||||
if rich_output:
|
||||
console.print("🐦 Fetching tweet %s...\n" % tweet_id)
|
||||
start = time.time()
|
||||
@@ -758,7 +747,7 @@ def show(ctx, index, max_count, full_text, output_file, as_json, as_yaml):
|
||||
config = load_config()
|
||||
rich_output = use_rich_output(as_json=as_json, as_yaml=as_yaml, compact=compact)
|
||||
try:
|
||||
client = _get_client_for_output(config, quiet=not rich_output)
|
||||
client = _get_client(config, quiet=not rich_output)
|
||||
if rich_output:
|
||||
console.print("🐦 Fetching tweet #%d (id: %s)...\n" % (index, tweet_id))
|
||||
start = time.time()
|
||||
@@ -796,7 +785,7 @@ def article(ctx, tweet_id, as_json, as_yaml, as_markdown, output_file):
|
||||
config = load_config()
|
||||
rich_output = use_rich_output(as_json=as_json, as_yaml=as_yaml, compact=False) and not as_markdown
|
||||
try:
|
||||
client = _get_client_for_output(config, quiet=not rich_output)
|
||||
client = _get_client(config, quiet=not rich_output)
|
||||
if rich_output:
|
||||
console.print("📰 Fetching article %s...\n" % tweet_id)
|
||||
start = time.time()
|
||||
@@ -856,7 +845,7 @@ def followers(screen_name, max_count, as_json, as_yaml):
|
||||
config = load_config()
|
||||
try:
|
||||
rich_output = use_rich_output(as_json=as_json, as_yaml=as_yaml)
|
||||
client = _get_client_for_output(config, quiet=not rich_output)
|
||||
client = _get_client(config, quiet=not rich_output)
|
||||
if rich_output:
|
||||
console.print("👤 Fetching @%s's profile..." % screen_name)
|
||||
profile = client.fetch_user(screen_name)
|
||||
@@ -889,7 +878,7 @@ def following(screen_name, max_count, as_json, as_yaml):
|
||||
config = load_config()
|
||||
try:
|
||||
rich_output = use_rich_output(as_json=as_json, as_yaml=as_yaml)
|
||||
client = _get_client_for_output(config, quiet=not rich_output)
|
||||
client = _get_client(config, quiet=not rich_output)
|
||||
if rich_output:
|
||||
console.print("👤 Fetching @%s's profile..." % screen_name)
|
||||
profile = client.fetch_user(screen_name)
|
||||
@@ -1062,7 +1051,7 @@ def status(as_json, as_yaml):
|
||||
config = load_config()
|
||||
try:
|
||||
rich_output = use_rich_output(as_json=as_json, as_yaml=as_yaml)
|
||||
client = _get_client_for_output(config, quiet=not rich_output)
|
||||
client = _get_client(config, quiet=not rich_output)
|
||||
profile = client.fetch_me()
|
||||
except RuntimeError as exc:
|
||||
payload = error_payload("not_authenticated", str(exc))
|
||||
@@ -1087,7 +1076,7 @@ def whoami(as_json, as_yaml):
|
||||
config = load_config()
|
||||
try:
|
||||
rich_output = use_rich_output(as_json=as_json, as_yaml=as_yaml)
|
||||
client = _get_client_for_output(config, quiet=not rich_output)
|
||||
client = _get_client(config, quiet=not rich_output)
|
||||
if rich_output:
|
||||
console.print("👤 Fetching current user...")
|
||||
profile = client.fetch_me()
|
||||
|
||||
@@ -76,8 +76,6 @@ def get_accept_language():
|
||||
# type: () -> str
|
||||
tag = _get_locale_tag()
|
||||
language = tag.split("-", 1)[0] or "en"
|
||||
if tag == language:
|
||||
return "%s,%s;q=0.9,en;q=0.8" % (tag, language)
|
||||
return "%s,%s;q=0.9,en;q=0.8" % (tag, language)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user