refactor: fix remaining code review issues on kabi-use

- _get_client: remove useless try/except that re-raised same error
- verify_cookies: increase timeout from 3s to 5s
- fetch_user: use _deep_get for URL extraction (consistent with
  _parse_user_result)
- formatter: remove no-op tweets_to_json wrapper and unused import
- _as_int/_as_float: filter.py now imports from config.py (dedup)
- CLI read commands: extract _fetch_and_display() to dedup
  favorite/search/likes/list_timeline
- _write_action: move load_config inside try block
- auth.py: add PEP 8 blank line after logger
This commit is contained in:
jackwener
2026-03-07 21:49:12 +08:00
parent df39a15d00
commit 625181b76c
5 changed files with 57 additions and 129 deletions

View File

@@ -21,6 +21,7 @@ from .constants import BEARER_TOKEN, USER_AGENT
logger = logging.getLogger(__name__)
def load_from_env() -> Optional[Dict[str, str]]:
"""Load cookies from environment variables."""
auth_token = os.environ.get("TWITTER_AUTH_TOKEN", "")
@@ -59,7 +60,7 @@ def verify_cookies(auth_token, ct0):
ctx = ssl.create_default_context()
try:
with urllib.request.urlopen(req, context=ctx, timeout=3) as resp:
with urllib.request.urlopen(req, context=ctx, timeout=5) as resp:
data = json.loads(resp.read().decode("utf-8"))
return {"screen_name": data.get("screen_name", "")}
except urllib.error.HTTPError as e: