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

@@ -8,12 +8,8 @@ from __future__ import annotations
from dataclasses import replace
import math
from typing import Mapping
# Type alias for filter weights dict
FilterWeights = Mapping[str, float]
from .config import _as_float, _as_int
DEFAULT_WEIGHTS = {
"likes": 1.0,
@@ -95,21 +91,3 @@ def _build_weights(raw_weights):
for key, default_value in DEFAULT_WEIGHTS.items():
merged[key] = _as_float(raw_weights.get(key), default_value)
return merged
def _as_int(value, default):
# type: (Any, int) -> int
"""Best-effort int conversion."""
try:
return int(value)
except (TypeError, ValueError):
return default
def _as_float(value, default):
# type: (Any, float) -> float
"""Best-effort float conversion."""
try:
return float(value)
except (TypeError, ValueError):
return default